Skip to content
~/mahadi hassan

Rate Limiter — Live

A distributed token-bucket rate limiter in NestJS + Redis with a live dashboard that shows requests getting throttled in real time.

2026—present
  • TypeScript
  • NestJS
  • Redis
  • Next.js

Overview

A distributed API rate limiter you can watch work. A Redis token-bucket limiter in NestJS, fronted by a live Next.js dashboard that visualises the bucket draining and requests flipping to HTTP 429 the instant traffic crosses the sustained rate.

How it works

Each request spends one token from a bucket that refills at a fixed rate — allowing a short burst while enforcing a steady long-run rate. The whole read-compute-write decision runs inside a single Redis Lua script, so concurrent requests across instances can't double-spend a token. Every decision is streamed to the browser over Server-Sent Events, which is what makes the bucket visible in real time.

// atomic in one round-trip — no lost updates under load
const [allowed, tokens] = await redis.tokenBucket(key, now, capacity, refill, 1);

Highlights

  • Token-bucket algorithm with an atomic Redis Lua script (no double-spend under concurrency)
  • Live SSE dashboard: token gauge, request stream, throughput chart, one-click traffic scenarios
  • Standard X-RateLimit-* and Retry-After headers
  • Proven three ways — unit (fake clock), integration (Testcontainers), and k6 load tests
  • One docker compose up runs the whole stack; CI on GitHub Actions

Comments

Loading comments…

More projects

~/projects
>_

EMPATHIKA — Enterprise Healthcare Platform

Scalable backend for an enterprise healthcare platform — secure NestJS + Fastify APIs on PostgreSQL & MongoDB, Redis caching, deep AWS integration, and Docker deployment, supporting patients, appointments, and medical records.

  • TypeScript
  • NestJS
  • Microservices
  • PostgreSQL
  • Redis
  • AWS
  • MongoDB