An end-to-end, fault-tolerant log ingestion and observability pipeline designed to handle massive concurrent traffic.
Built using an event-driven architecture, LogStream decouples ingestion, processing, storage, and visualization layers to ensure scalability, resilience, and near real-time observability under heavy load.
- High-throughput asynchronous log ingestion
- Redis Streams-based event pipeline
- Consumer Group architecture for concurrent workers
- Real-time observability dashboard using WebSockets
- Infinite scrolling searchable log explorer
- SHA-256 based deduplication
- Batch database insertion using
executemany - Fault-tolerant replay handling using Redis Pending Entries List (PEL)
- PostgreSQL-backed persistent storage
- Full-text log searching
- Live ingestion velocity monitoring
- Horizontally scalable worker architecture
┌────────────────────┐
│ Client Apps │
└─────────┬──────────┘
│
▼
┌────────────────────┐
│ FastAPI Ingestion │
│ Layer │
└─────────┬──────────┘
│
▼
┌────────────────────┐
│ Redis Streams │
│ Consumer Groups │
└─────────┬──────────┘
│
┌───────────┴───────────┐
▼ ▼
┌──────────────┐ ┌──────────────┐
│ Worker #1 │ │ Worker #2 │
│ asyncio │ │ asyncio │
└──────┬───────┘ └──────┬───────┘
│ │
└──────────┬───────────┘
▼
┌────────────────────┐
│ PostgreSQL │
│ Persistent DB │
└────────────────────┘
│
▼
┌────────────────────┐
│ Redis Pub/Sub │
│ Live Metrics Bus │
└─────────┬──────────┘
▼
┌────────────────────┐
│ React Dashboard │
│ WebSocket Client │
└────────────────────┘
- FastAPI
- Python 3.11+
- SQLAlchemy
- asyncpg
- asyncio
- Redis Streams
- Redis Pub/Sub
- PostgreSQL
- Alembic
- uv
- React
- TypeScript
- Tailwind CSS
- Recharts
- Lucide Icons
Instead of writing directly to PostgreSQL during ingestion, logs are first pushed into Redis Streams.
This decouples:
- API responsiveness
- database writes
- processing workload
Result:
- sub-millisecond ingestion latency
- higher throughput
- resilient backpressure handling
Every log message is hashed using SHA-256 before insertion.
Combined with PostgreSQL:
ON CONFLICT DO NOTHINGworkers can safely replay failed batches without corrupting the database.
This makes recovery from worker crashes deterministic and safe.
Workers collect logs in batches of 100 and use:
executemany()instead of individual insert queries.
This reduces:
- database round trips
- transaction overhead
- disk sync pressure
Result:
- significantly higher throughput
- lower database CPU utilization
Redis Consumer Groups allow multiple workers to process logs concurrently without duplication.
Scaling becomes simple:
uv run processor.pyRun multiple instances across machines or containers.
Instead of continuously polling PostgreSQL for updates:
- workers publish lightweight metrics to Redis Pub/Sub
- FastAPI listens to Pub/Sub
- WebSocket broadcasts updates to connected clients
Result:
- near-zero database load during live monitoring
- efficient real-time dashboard streaming
Create a .env file in the project root:
REDIS_HOST=localhost
REDIS_PORT=6379
DB_HOST=localhost
DB_PORT=5432
DB_USER=postgres
DB_PASS=your_password
DB_NAME=logger
DATABASE_URL=postgresql://postgres:root@localhost:5432/loggerpip install uvuv venvActivate environment:
source .venv/bin/activate.venv\Scripts\activateIf using pyproject.toml:
uv syncInitialize Alembic:
uv run alembic init alembicCreate migration:
uv run alembic revision --autogenerate -m "create logs table"Run migrations:
uv run alembic upgrade headuv run uvicorn app.main:app --reload --port 8000uv run processor.pyRun multiple workers in separate terminals for horizontal scaling.
Navigate into frontend directory:
npm install -g pnpm
cd clientInstall dependencies:
pnpm installRun development server:
pnpm run devThe easiest way to run LogStream is using Docker Compose. This starts all required services automatically, including PostgreSQL, Redis, the backend API, frontend, worker, and database migrations.
- Docker
- Docker Compose
Verify your installation:
docker --version
docker compose versiongit clone https://github.com/RahulGIT24/Scalable-Log-Processor
cd Scalable-Log-ProcessorInside the log_processor directory, create a file named:
log_processor/.docker.env
Add the following configuration:
REDIS_HOST=redis
REDIS_PORT=6379
DB_HOST=postgres
DB_PORT=5432
DB_USER=postgres
DB_PASS=root
DB_NAME=logger
DATABASE_URL=postgresql://postgres:root@postgres:5432/logger
TABLE_NAME=logsNote: Inside Docker containers, services communicate using the Docker Compose service names (
postgres,redis) rather thanlocalhost.
docker compose builddocker compose upRun in detached mode if preferred:
docker compose up -dDocker Compose automatically starts:
- PostgreSQL
- Redis
- FastAPI Backend
- React Frontend (served using Nginx)
- Background Log Processing Worker
- Alembic Migration Service
No additional setup is required.
| Service | URL |
|---|---|
| Frontend | http://localhost:5173 |
| Backend API | http://localhost:8000 |
Stop all containers:
docker compose downTo also remove the PostgreSQL volume:
docker compose down -vIf Dockerfiles or dependencies change:
docker compose build --no-cache
docker compose upDocker Compose runs the following services:
- frontend — React application served via Nginx
- backend — FastAPI REST API
- worker — Redis Streams consumer responsible for processing logs
- migrate — Alembic migration runner
- postgres — PostgreSQL database
- redis — Redis Streams and Pub/Sub server
A stress testing script is included to simulate high concurrent traffic.
Run:
uv run stress_test.pyDefault configuration:
- 500 concurrent connections
- 5000 log messages
Expected behavior:
- API accepts requests immediately
- Redis buffers ingestion spikes
- workers batch-process logs asynchronously
- dashboard displays live ingestion spikes in real time
Push a log into Redis Stream.
Example payload:
{
"log_level": "ERROR",
"message": "Database connection failed",
"tags": ["DATABASE", "PROD"]
}Returns aggregated counts grouped by log level.
Search historical logs with pagination.
Example:
/api/analytics/search?search=database&limit=50&offset=0Streams:
- ingestion metrics
- live logs
- processing statistics
- Live WebSocket updates
- Infinite scroll log explorer
- Debounced full-text search
- Real-time ingestion velocity graph
- Log level aggregation cards
- Responsive observability UI
- Search without database polling
Enjoy Stress Testing LogStream in action:
Under stress testing:
- ingestion remains non-blocking
- Redis absorbs traffic spikes
- workers process asynchronously
- PostgreSQL write amplification remains low due to batching
The architecture is designed around:
- backpressure tolerance
- fault recovery
- horizontal scalability
- observability-first design