← Lessons

quiz vs the machine

Gold1380

System Design

The Sliding Window Log

Store every request timestamp so the limit is exact at any instant, at the cost of memory.

5 min read · core · beat Gold to climb

What it does

A sliding window log keeps the timestamp of every request a client made within the trailing window. On each new request the limiter drops timestamps older than the window, counts what remains, and allows the request only if the count is below the limit. Then it appends the new timestamp.

Because the window slides continuously with real time, there is no fixed seam to exploit. The count always reflects exactly how many requests landed in the last N seconds.

What it costs

  • Memory grows with the request rate: a client allowed one hundred per minute needs up to one hundred stored timestamps.
  • Each request does cleanup work to evict expired entries, often backed by a sorted set.

When it fits

  • Low volume, high value endpoints where precision matters more than storage, such as login or payment flows.
  • Cases where the fairness of an exact window justifies the extra bookkeeping.

Key idea

The sliding window log is exact because it remembers every timestamp, but its memory grows with the request rate.

Check yourself

Answer to earn rating on the learn ladder.

1. Why is the sliding window log exact?

2. What is its main cost?