A production-grade, containerized distributed logging and telemetry pipeline built from scratch in Go, featuring asynchronous Kafka message buffering, Redis-backed distributed rate-limiting, distributed tracing, PostgreSQL batch ingestion, and real-time stream analytics.
[ Log Forwarder Agent ] │ (Gzip / Batched HTTP POST) ▼ [ Ingestion Gateway (Gin API) ] ──(Redis Token Bucket Rate Limiter) │ (Kafka Record Headers + X-Correlation-ID) ▼ [ Apache Kafka Cluster (KRaft) ] │ ▼ [ Stream Analytics & Persistence Engine ] ├──> Real-time Golden Signals (RPS, Error Rates) └──> High-Velocity Batch Copy (PostgreSQL system_logs)
- High-Performance Ingestion Gateway: Built on Gin using radix-tree routing, custom tracing middleware, and stream decompression to safely handle high-throughput payloads without memory spikes.
- Distributed Tracing & Correlation: Generates unique UUID trace identifiers (
X-Correlation-ID) at the HTTP boundary and propagates them across Kafka record metadata into background workers. - Asynchronous Decoupling via Kafka: Decouples API endpoints from database writes using Kafka partitions and consumer groups, complete with backpressure load-shedding.
- Redis Distributed Rate Limiting: Enforces atomic token-bucket rate limits per client IP to protect downstream services from traffic spikes and abuse.
- Real-Time Stream Analytics & Golden Signals: Tracks live service throughput (RPS), calculates error percentages across sliding windows, and logs anomalous traffic spikes.
- Optimized Database Persistence: Buffers streaming telemetry logs and flushes them in high-velocity batches (
pq.CopyIn) into PostgreSQL with composite indexing on timestamps and services. - Production Observability: Fully instrumented with Prometheus metrics scraping and Grafana dashboards running inside a unified Docker Compose network.
- Language: Go (Golang)
- API Framework: Gin (
github.com/gin-gonic/gin) - Message Broker: Apache Kafka (Confluent CP-Kafka KRaft mode)
- Cache & Rate Limiting: Redis (
redis:7-alpine) - Relational Storage: PostgreSQL 15 (
lib/pq) - Observability: Prometheus & Grafana
- Containerization: Docker & Docker Compose (Multi-stage builds)
- Docker & Docker Compose installed
- Go (version 1.21+)
git clone [https://github.com/YOUR_GITHUB_USERNAME/distributed-logger.git](https://github.com/YOUR_GITHUB_USERNAME/distributed-logger.git)
cd distributed-logger
2. Spin Up the Infrastructure & Microservices Stack
PowerShell
docker-compose down
docker-compose build --no-cache
docker-compose up -d
3. Verify Container Health
PowerShell
docker-compose ps
🧪 Testing the Pipeline
Send an End-to-End Test Log Batch
PowerShell
Invoke-RestMethod -Uri "http://localhost:8080/api/v1/ingest" `
-Method Post `
-ContentType "application/json" `
-Body '[
{"timestamp": 1722864000, "level": "INFO", "service": "order-service", "message": "Order placed successfully"},
{"timestamp": 1722864001, "level": "ERROR", "service": "payment-service", "message": "Gateway timeout during checkout"}
]'
Inspect PostgreSQL Persistence
PowerShell
docker exec -it logger_postgres psql -U postgres -d logger_db -c "SELECT id, correlation_id, service, level, message, created_at FROM system_logs ORDER BY created_at DESC LIMIT 5;"
📊 Observability Dashboards
Prometheus UI: http://localhost:9090
Grafana Dashboard: http://localhost:3000 (Login: admin / admin)
👤 Author
Chimpiri Sanketh
Full Stack & Systems Software Engineer