A high-performance, event-driven social media feed system built for scale. Features Fan-Out on Write, Idempotency, and Smart Caching.
- ⚡ Event-Driven Architecture - Decoupled services using Kafka for asynchronous processing.
- 📡 Fan-Out on Write - Efficient pre-computed feeds for high-read throughput.
- 🛡️ Resilience - Idempotent processing, Dead Letter Queues (DLQ), and Graceful Shutdowns.
- 🚀 Smart Caching - Redis "Cache-Aside" pattern for hot feeds.
- 📊 Observability - Prometheus metrics for request rates, latencies, and throughput.
This project includes a Makefile for easy management.
Starts PostgreSQL, Kafka, Zookeeper, and Redis.
make infraRun these in separate terminals:
Terminal 1: API Service
make run-api
# Access at http://localhost:8080Terminal 2: Processor Service
make run-processorRuns the End-to-End test to verify the full flow (Post -> Kafka -> Processor -> DB).
make testgraph TD
User[Client] -->|HTTP POST| API[API Service]
API -->|Produce Event| Kafka{Apache Kafka}
API -->|Read/Write| DB[(PostgreSQL)]
API -->|Cache Read| Redis[(Redis)]
Kafka -->|Consume Event| Proc[Processor Service]
Proc -->|Fan-Out Batch Insert| DB
Proc -->|Update/Invalidate| Redis
Prometheus -->|Scrape| API
Prometheus -->|Scrape| Proc
Tested on a single development machine (MacBook Air M4) with all services running locally via Docker.
| Metric | Throughput | Latency (Avg) | Notes |
|---|---|---|---|
| Write (Create Post) | ~1,200 RPS | ~80ms | Async processing via Kafka |
| Read (Get Feed) | ~3,800 RPS | ~5ms | Redis Cache-Aside Hit |
System demonstrates high read scalability due to caching and decoupled write/fan-out architecture.
| Method | Endpoint | Description |
|---|---|---|
POST |
/posts |
Create a new post (Triggers Event) |
GET |
/feeds/{user_id} |
Get user's feed (Cached) |
POST |
/follow |
Follow a user |
GET |
/metrics |
Prometheus Metrics |
DLQ Inspector View failed messages in the Dead Letter Queue:
make dlq