A production-grade, non-blocking telemetry engine built for ultra-fast event ingestion (<20ms), dynamic Redis queue batching, complex analytical SQL windowing, and real-time dashboard observability.
π Live Dashboard: https://loggscale.vercel.app
When thousands of mobile or web clients generate clickstreams, telemetry events, and server logs simultaneously, traditional synchronous API endpoints attempt to write each event directly into the database one by one. This causes:
- Database Connection Starvation: Exhaustion of PostgreSQL connection pools under traffic spikes.
- Client Latency Overhead: HTTP responses delayed by 200msβ800ms while waiting for DB disk disk sync (
fsync). - Cascading Failures: Unhandled DB lock timeouts cascading into frontend application crashes.
LogScale solves this bottleneck by completely decoupling HTTP payload receipt from database storage:
- The Ingestion API validates incoming JSON via Zod and enqueues the payload into Redis BullMQ in <7ms, instantly returning
202 Accepted. - A background BullMQ Batch Consumer drains queue items in dynamic chunks (200β500 items/batch) and performs single bulk
COPY/createManyoperations into PostgreSQL. - Analytical SQL queries utilize time-series compound indexes, window functions (
LEAD(),LAG()), andPERCENTILE_CONTcalculations to serve sub-second analytics dashboards.
flowchart TD
subgraph Clients & Ingestion
A[SDK / Client App] -->|1. POST /api/v1/telemetry/ingest| B[NestJS Ingestion Controller]
B -->|2. Zod Validation| C[Fast Validation Guard]
C -->|3. Push Job <7ms| D[Redis 7 BullMQ Queue]
B -->|4. Return 202 Accepted| A
end
subgraph Async Processing & Storage
D -->|5. Dynamic Batch Drain 200-500 items| E[BullMQ Batch Consumer]
E -->|6. Bulk Copy / createMany| F[(PostgreSQL 16 DB)]
G[NestJS Cron Scheduler] -->|7. Nightly Rollup Job| H[(DailyAggregates Table)]
end
subgraph Real-Time Engine & Analytics
D -->|8. SSE Live Stream Pipe| I[Server-Sent Events Controller]
F -->|9. SQL Window Functions & PERCENTILE_CONT| J[Analytics Query Engine]
I -->|10. Live Events| K[Next.js 15 Web Dashboard]
J -->|11. Funnel & Latency Metrics| K
end
- Accepts single events or array batches at
POST /api/v1/telemetry/ingest. - Authorizes incoming requests via SHA-256 hashed API keys (
X-API-Key). - Validates payload structure using Zod schemas and pushes to Redis queue in <7ms.
- Prevents database connection starvation by buffering traffic bursts inside Redis.
- Concurrently drains queue items across worker threads using dynamic batching (200β500 records per database transaction).
- Conversion Funnels: Multi-step conversion drop-offs calculated using SQL Common Table Expressions (CTEs) and timestamp window constraints.
- Cohort Retention Matrix: Weekly user retention heatmaps computed via SQL date truncation (
DATE_TRUNC('week', ...)) and relative week offset grouping. - System Telemetry Latency: Computes p50, p95, and p99 latency percentiles and error percentages using PostgreSQL
PERCENTILE_CONT(0.50|0.95|0.99) WITHIN GROUP.
- Built with Next.js 15 App Router, React, Tailwind CSS, and Lucide Icons.
- Interactive Simulator: Fire high-throughput event spikes directly from the UI.
- Real-Time Live Pipe: Server-Sent Events (SSE) stream incoming logs onto the dashboard without page refreshes.
- Advanced Log Explorer: Search logs by endpoint or status code (
2XX,4XX,5XX) and expand rows to inspect raw JSON trace metadata. - SLA & Error Budget Tracker: Real-world 99.9% Uptime availability SLA meter and error budget consumption gauge.
- Helmet HTTP Security Headers: Injects headers for XSS protection, X-Frame-Options (DENY Clickjacking), and HSTS.
- Rate Limiting & Anti-DDoS: Throttles API endpoints to 120 req/min per IP using
@nestjs/throttlerto block brute-force and DDoS bots. - Strict Payload Body Size Limits: Restricts JSON body payload parsing to 2MB to prevent OOM memory buffer overflow attacks.
- Zero-Credential Error Redaction: Employs an
AllExceptionsFilterthat redacts database connection strings, passwords, and API keys from error outputs and stack trace logs. - TLS/SSL Encryption: Enforces encrypted TLS transport for Cloud PostgreSQL (
sslmode=require) and Cloud Redis (rediss://).
LogScale uses PostgreSQL 16 with custom time-series indexing strategies:
model RawEvent {
id String @id @default(uuid())
orgId String @map("org_id")
eventName String @map("event_name")
userId String @map("user_id")
properties Json @default("{}")
timestamp DateTime @default(now())
organization Organization @relation(fields: [orgId], references: [id], onDelete: Cascade)
// Compound time-series indexes for sub-second query performance
@@index([orgId, timestamp(sort: Desc)])
@@index([orgId, eventName, timestamp(sort: Desc)])
@@index([orgId, userId, timestamp(sort: Desc)])
@@map("raw_events")
}
model TelemetryLog {
id String @id @default(uuid())
orgId String @map("org_id")
serviceName String @map("service_name")
endpoint String
statusCode Int @map("status_code")
durationMs Float @map("duration_ms")
meta Json? @default("{}")
timestamp DateTime @default(now())
organization Organization @relation(fields: [orgId], references: [id], onDelete: Cascade)
@@index([orgId, timestamp(sort: Desc)])
@@index([orgId, serviceName, timestamp(sort: Desc)])
@@index([orgId, statusCode, timestamp(sort: Desc)])
@@map("telemetry_logs")
}| Metric | Result | Target Standard | Status |
|---|---|---|---|
| Ingestion HTTP Response Time | 4ms β 7ms | < 20ms |
π’ Exceeds Standard |
| Ingestion Throughput | 5,000+ events/sec | > 1,000 req/sec |
π’ Passed |
| Worker Batch Insert Speed | 500 records in 12ms | < 50ms |
π’ Passed |
| Funnel Query Latency (100k events) | 24ms | < 100ms |
π’ Passed |
| p95/p99 Percentile Calculation | 18ms | < 50ms |
π’ Passed |
LogScale/
βββ docker-compose.yml # PostgreSQL 16 & Redis 7 container configuration
βββ README.md # Architectural design & setup guide
βββ apps/
β βββ backend/ # NestJS API Engine & BullMQ Background Worker
β β βββ prisma/
β β β βββ schema.prisma # Time-series indexed database schema
β β β βββ seed.ts # Demo data seeding script
β β βββ src/
β β βββ modules/
β β β βββ auth/ # API Key hashing & Org management
β β β βββ ingestion/ # Non-blocking 202 Accepted ingestion controller
β β β βββ worker/ # BullMQ queue consumer (batch inserts)
β β β βββ analytics/ # Funnel, Cohort & Latency SQL query services
β β β βββ cron/ # Daily rollup cron into DailyAggregates
β β β βββ stream/ # Server-Sent Events (SSE) live event stream
β βββ frontend/ # Next.js 15 Web Dashboard
β βββ app/ # App Router pages and styling
β βββ components/ # Funnel, Heatmap, Latency, Log Explorer & Error Budget UI
βββ packages/
βββ shared/ # Shared Zod schemas & TypeScript interfaces
git clone https://github.com/adityaagrawall/LogScale.git
cd LogScale
npm install
npm run build --workspace=packages/shareddocker-compose up -dnpm run db:push --workspace=apps/backend
npm run db:seed --workspace=apps/backend# Terminal 1: NestJS Backend API (http://localhost:3001)
npm run dev:backend
# Terminal 2: Next.js 15 Web Dashboard (http://localhost:3000)
npm run dev:frontendSend an event payload to test the non-blocking ingestion pipeline:
curl -X POST http://localhost:3001/api/v1/telemetry/ingest \
-H "Content-Type: application/json" \
-H "x-api-key: lx_live_demo1234567890abcdef1234567890" \
-d '{
"events": [
{
"eventName": "page_view",
"userId": "user_1001",
"properties": { "path": "/pricing" }
}
],
"telemetry": [
{
"serviceName": "auth-service",
"endpoint": "/api/v1/auth/login",
"statusCode": 200,
"durationMs": 48.2
}
]
}'Returns HTTP 202 Accepted in <7ms:
{
"status": "accepted",
"statusCode": 202,
"message": "Payload successfully enqueued in 4ms",
"jobId": "14",
"queuedItems": {
"eventsCount": 1,
"telemetryCount": 1
}
}This project is open-source and available under the MIT License.