Lessons in this course (14)

9. Rate limiting, search, storage and CDNs

IntermediateMediumLesson 9 of 14

Rate limiting algorithms:

AlgorithmIdea
Fixed windowCount requests per minute window — simple, bursty at edges
Sliding window log/counterSmoother limit over a moving window
Token bucketTokens refill at a rate; each request takes one; allows short bursts — most common
Leaky bucketRequests leave at a constant rate — smooths traffic

Distributed rate limiting keeps counters in Redis (atomic INCR with expiry or Lua scripts). ASP.NET Core has AddRateLimiter with fixed window, sliding window, token bucket and concurrency limiters; return 429 with Retry-After.

Search: an inverted index (word → documents) in Elasticsearch/Azure AI Search, fed asynchronously from the database (change events); supports full text, typo tolerance, facets and ranking.

Files and media: store in object storage (Blob/S3), keep only metadata + URL in the database, upload directly from the client with pre-signed/SAS URLs, serve through a CDN, process asynchronously (thumbnails, virus scan, transcoding) via a queue.