Bird
Raised Fist0

Fixed Window vs Sliding Window Counter - Trade-offs

HLDmediumInterview freq: common
Choose your preparation mode4 modes available
▶
Request Trace
Step 1/5
API Gateway / Proxy

Receives client HTTP request

Forwards request to Rate Limiter Service for quota check

Protocol:HTTP
BeforeClient request just arrived at API Gateway
AfterRequest forwarded to Rate Limiter Service
Rate Limiter Service

Queries Redis Fixed Window Store

Performs INCR on fixed window key for current time bucket

Protocol:Redis INCR
BeforeCurrent fixed window count unknown
AfterFixed window count incremented atomically
Rate Limiter Service

Queries Redis Sliding Window Store

Reads timestamps in sorted set within sliding window range

Protocol:Redis ZRANGE/ZADD
BeforeSliding window timestamps not updated for this request
AfterSliding window timestamps updated with current request time
Rate Limiter Service

Decides if request exceeds rate limit

Compares counts from fixed and sliding windows to thresholds

Protocol:Internal logic
BeforeCounts from Redis stores retrieved
AfterRequest allowed or rejected based on rate limits
Rate Limiter Service

Logs request count to Persistent Storage (Cassandra)

Writes usage data for auditing and analytics

Protocol:CQL
BeforeRequest decision made
AfterRequest usage durably logged in Cassandra
🏗️
Architecture Diagram
Architecture Diagram
┌───────────────────────┐
│  API Gateway / Proxy  │
└────────────┬──────────┘
             │ HTTP Request
             ▼
┌───────────────────────────┐
│   Rate Limiter Service    │
└───────┬─────────┬─────────┘
        │         │
        │ Redis GET/INCR       Redis ZRANGE/ZADD
        ▼         ▼
┌───────────────────────┐  ┌────────────────────────┐
│ Redis Fixed Window     │  │ Redis Sliding Window    │
│ Store                 │  │ Store                  │
└────────────┬──────────┘  └─────────────┬──────────┘
             │                       │
             │                       │
             └──────────────┬────────┘
                            │
                            ▼
               ┌─────────────────────────────┐
               │ Persistent Storage (Cassandra)│
               └─────────────────────────────┘

This architecture compares Fixed Window and Sliding Window counters for rate limiting. The API Gateway forwards requests to the Rate Limiter Service, which queries Redis Fixed Window Store using atomic INCR commands to count requests in discrete time buckets. Simultaneously, it queries Redis Sliding Window Store, which maintains sorted sets of timestamps for fine-grained sliding window counts. The Rate Limiter Service then decides if the request exceeds limits based on these counts. Finally, it logs usage data to Cassandra for durable auditing. Fixed Window counters are simpler but can cause burstiness at window edges, while Sliding Window counters provide smoother rate limiting at the cost of more complex storage and computation.

Primary Focus

✓

Practice

(1/5)
1. In a distributed database, at Step 4 the coordinator node receives conflicting writes from two partitions during a network split. What state does the coordinator enter immediately after Step 4?
easy
A. Coordinator marks the writes as conflicting and delays commit until partition heals
B. Coordinator commits both writes immediately to maintain availability
C. Coordinator rejects all writes to maintain consistency during partition
D. Coordinator forwards writes to a third node to resolve conflicts synchronously

Solution

  1. Step 1: Trace coordinator behavior at Step 4

    The coordinator detects conflicting writes from partitions and cannot commit both safely.
  2. Step 2: Understand conflict resolution

    It marks writes as conflicting and delays commit until partitions heal to avoid inconsistency.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Coordinator defers conflicting writes until partition resolution [check]
Hint: Coordinator delays conflicting writes until partition heals [check]
Common Mistakes:
2. A distributed system requires generating unique IDs for millions of records per second across multiple data centers without coordination delays. Which ID generation strategy best fits this scenario?
easy
A. Use UUIDs generated independently by each data center
B. Use auto-increment IDs generated independently by each data center
C. Use custom IDs generated by a single global coordinator service
D. Use auto-increment IDs generated by a single centralized database node

Solution

  1. Step 1: Identify ID generation constraints

    Millions of IDs per second across multiple data centers require decentralized generation to avoid coordination delays.
  2. Step 2: Evaluate options for distributed uniqueness

    Auto-increment IDs from a single node (A) cause bottlenecks; custom IDs from a global coordinator (C) add latency; auto-increment per data center (D) risks collisions. UUIDs (B) are globally unique without coordination.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    UUIDs enable decentralized unique ID generation [check]
Hint: Decentralized unique IDs at scale -> UUIDs [check]
Common Mistakes:
3. Given the need to quickly detect and rollback misconfigurations causing route leaks, which architecture is best suited for this scenario?
medium
A. Manual configuration changes with peer review before deployment
B. A centralized configuration management system with automated rollback triggers
C. A fully decentralized BGP control plane with no central oversight
D. A distributed consensus system that delays route announcements until quorum

Solution

  1. Step 1: Evaluate manual review trade-offs

    Manual peer review slows deployment but reduces risk of misconfiguration propagation.
  2. Step 2: Compare alternatives

    Decentralized control (A) lacks oversight; centralized rollback (B) is ideal but may introduce complexity; consensus delays (D) add latency.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Manual review trades speed for safety in rollback scenarios [check]
Hint: Manual review trades speed for safety [check]
Common Mistakes:
4. If the Ticket Server crashes after allocating an ID block but before the client acknowledges, what is the exact failure observed in the system?
medium
A. Clients receive duplicate IDs because the block is reissued without tracking
B. Some ID blocks are lost, causing gaps in the global ID sequence but no duplicates
C. Clients block indefinitely waiting for the Ticket Server response, halting ID generation
D. Clients generate IDs locally without coordination, risking collisions

Solution

  1. Step 1: Understand Ticket Server crash impact

    If the server crashes post-allocation but pre-acknowledgment, it cannot confirm the block was assigned.
  2. Step 2: Trace ID block state

    The allocated block is effectively lost, causing gaps in the global ID sequence, but clients do not reuse lost blocks, preventing duplicates.
  3. Final Answer:

    Option B -> Option B
  4. Quick Check:

    Crash after allocation -> lost ID blocks, no duplicates [check]
Hint: Crash post-allocation loses blocks, no duplicate IDs generated [check]
Common Mistakes:
5. At 10x traffic scale, which component of a global server load balancing system is most likely to fail first and why?
hard
A. The data center ingress routers, since network bandwidth scales linearly and saturates quickly
B. The health monitoring system, due to increased frequency of health checks overwhelming it
C. The GSLB control plane, as it struggles to process and update routing decisions for all data centers in real-time
D. The DNS servers, because they cannot handle the surge in query volume and caching limits failover speed

Solution

  1. Step 1: Analyze scaling challenges

    Health monitoring (The health monitoring system, due to increased frequency of health checks overwhelming it) scales with checks but can be optimized; control plane (The GSLB control plane, as it struggles to process and update routing decisions for all data centers in real-time) is distributed and designed for scale; ingress routers (The data center ingress routers, since network bandwidth scales linearly and saturates quickly) scale with network upgrades.
  2. Step 2: Identify DNS bottleneck

    DNS servers face query volume spikes and caching TTLs limit failover responsiveness, making them the first to fail under 10x load.
  3. Final Answer:

    Option D -> Option D
  4. Quick Check:

    DNS query volume and caching limits cause first failure at scale [check]
Hint: DNS query volume overloads servers first at scale [check]
Common Mistakes:
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard