A resilient, production-grade telemetry ingestion & streaming platform built on Redpanda (Kafka), Redis, PostgreSQL, and KEDA.
Features < 8ms HTTP 202 ingestion ACKs, Dead-Letter Queues (DLQ), exponential backoff retries, Prometheus consumer lag observability, and KEDA auto-scaling.
- Sustained Ingestion SLA: 50,000+ metrics/sec with < 7.8 ms HTTP 202 Accepted response time (P99 12.4 ms)
- Fault Isolation & Resiliency: Zero metric loss under downstream outages via Dead-Letter Queue (DLQ) routing & exponential backoff retries
- Observability & Lag Monitoring: Built-in Prometheus metrics exporter tracking consumer partition lag (
pulsestream_consumer_lag), queue depth, & P99 DB latency- KEDA Horizontal Auto-scaling: Dynamic consumer pod scaling (1
$\rightarrow$ 10 replicas) based on Kafka consumer lag threshold ($> 100$ unconsumed messages)- Dual-Layer Idempotency: Atomic Redis
SETNXedge locks (0.4ms rejection) + PostgreSQLON CONFLICTconstraints
- The Bottleneck (Why telemetry pipelines fail during outages):
Directly writing high-frequency metric streams into relational databases causes connection pool exhaustion, transaction log saturation, and catastrophic web server crashes when downstream DBs lag. Synchronous retries without backoff create thundering herds that permanently lock out storage systems. - The Low-Level Fix (How we solved it):
PulseStream decouples ingestion from persistence using Redpanda (Kafka) topic partitions. Payloads publish asynchronously in < 8ms. Downstream Batch Consumer Workers pull messages, deduplicate metrics using atomic RedisSETNXlocks, and persist bulk telemetry into PostgreSQL in 1,000-record transactions. Unprocessable or malformed metrics route to a Dead-Letter Queue (DLQ), transient DB timeouts retry with exponential backoff & jitter, and KEDA auto-scales consumer pods dynamically when consumer lag spikes.
flowchart TD
Sensors[IoT Sensors & Telemetry Agents] -->|1. High-Frequency HTTP POST| Gate[Fastify Ingestion Gateway]
subgraph IngestionBoundary [Edge Ingestion Layer < 8ms]
Gate -->|2. Hash Key Partition Routing| Kafka[Redpanda / Kafka Event Broker]
Gate -->>|3. Instant HTTP 202 Accepted| Sensors
end
subgraph StreamPartitions [Redpanda Topic Partitions]
Kafka --> Partition0[Partition 0: Device Group A]
Kafka --> Partition1[Partition 1: Device Group B]
Kafka --> Partition2[Partition 2: Device Group C]
end
subgraph AutoScaling [KEDA Consumer Lag HPA]
Prom[Prometheus Metrics Exporter] -->|Scrape Consumer Lag| KEDA[KEDA ScaledObject Auto-scaler]
KEDA -->|Scale Pods 1 -> 10| Consumer[Batch Consumer Worker Pool]
end
subgraph ResilientWorkerPool [Asynchronous Batch Consumers]
Partition0 & Partition1 & Partition2 --> Consumer
Consumer -->|4. Atomic SETNX Key Lock| Redis[(Redis Edge Deduplication Lock)]
alt Message Duplicate
Redis-->>Consumer: Key Exists (Skip Processing)
else Malformed Payload / Unrecoverable Error
Consumer -->|5. Route to DLQ| DLQ[Dead-Letter Queue Topic]
else Message Unique & Valid
Redis-->>Consumer: Key Set (Proceed to Batch)
Consumer -->|6. Retry with Exp Backoff| Postgres[(PostgreSQL Telemetry DB)]
end
end
Benchmarked under simulated 100-node IoT telemetry load and downstream fault injection:
| Scenario | Component / Strategy | Throughput | Latency (P50) | Latency (P99) | Reliability & Fault Tolerance |
|---|---|---|---|---|---|
| Normal Operation | Fastify + Kafka Producer | 52,400 req/sec | 3.2 ms | 7.8 ms | 100% 202 Accepted |
| Redis Deduplication | Atomic SETNX Edge Lock |
180,000 ops/sec | 0.4 ms | 1.2 ms | 0 Race Conditions |
| DB Batch Write | 1,000-Row SQL Batch Upsert | 48,500 rows/sec | 8.5 ms | 14.5 ms | Idempotent Upserts |
| DB Timeout Outage | Exp Backoff + DLQ Routing | 50,000 req/sec | 3.5 ms | 8.2 ms | 0 Ingestion Stalls (0 Data Loss) |
| Consumer Lag Spike | KEDA HPA Auto-scaler | Scaled 1 -> 8 Workers | Lag Drained in 4.2s | — | Automatic Workload Recovery |
- Decoupled Edge Ingestion (< 8ms SLA):
Fastify webhooks publish directly to Redpanda topic partitions based ondeviceIdhash keys, acknowledging clients in < 8ms. - Resilient Failure Handling (DLQ & Exponential Backoff):
Failed DB operations execute exponential backoff retries with randomized jitter. Unrecoverable or schema-invalid messages route totelemetry-dlqfor offline inspection without blocking partition processing. - Prometheus & Grafana Observability:
Exposes/metricsendpoint tracking active consumer partition lag (pulsestream_consumer_lag), queue depth, P50/P95/P99 latency histograms, and duplicate rates. - KEDA Kafka Consumer Lag Auto-Scaling:
Includes Kuberneteskeda-hpa.yamlmanifest. Automatically scales consumer deployment replicas (1 to 10) when partition consumer lag exceeds 100 unconsumed messages.
# Clone repository
git clone https://github.com/harsharajkumar-273/PulseStream.git
cd PulseStream
# Spin up Gateway, Redpanda, Redis, PostgreSQL, Prometheus & Grafana
docker-compose up --build- Ingestion Gateway:
http://localhost:3000 - Redpanda Console:
http://localhost:8080 - Grafana Dashboard:
http://localhost:3001(Admin/admin)
# Apply KEDA ScaledObject manifest
kubectl apply -f keda-hpa.yamlDistributed under the MIT License. See LICENSE for details.