- Published on
Hybrid Cloud vs All-Cloud Storage - System Design Interview Guide
Table of Contents
- ?? Token Bucket vs Leaky Bucket (Burst vs Smooth)
- ?? Token Bucket (Burst-Friendly / Flexible)
- ?? Core Idea
- ?? Key Properties
- ? Pros
- ? Cons
- ??? Architecture Decisions
- ?? Signals / When to Use
- ?? FAANG Interview Q&A
- ?? Memory Script (Token Bucket)
- ?? Leaky Bucket (Smooth / Strict Control)
- ?? Core Idea
- ?? Key Properties
- ? Pros
- ? Cons
- ??? Architecture Decisions
- ?? Signals / When to Use
- ?? FAANG Interview Q&A
- ?? Memory Script (Leaky Bucket)
- ?? Direct Comparison (High Signal)
- ?? Architecture Decision Rule (FAANG Shortcut)
- 1. Do you want to allow bursts?
- 2. Need smooth constant rate?
- 3. User experience sensitive?
- ?? Advanced Insights (IMPORTANT)
- ?? Real systems combine both
- ?? Distributed System Hint
- ?? Final 10-sec Brain Hack
?? Token Bucket vs Leaky Bucket (Burst vs Smooth)
?? Token Bucket (Burst-Friendly / Flexible)
?? Core Idea
Tokens accumulate ? spend tokens to send data ?? Allows bursts if tokens are saved
?? Key Properties
- Tokens added at fixed rate (r)
- Bucket has max capacity (b)
- Request allowed only if token exists
? Pros
- Handles burst traffic
- Flexible rate control
- Better user experience (no strict throttling)
? Cons
- Slightly more complex (token tracking)
- Can allow sudden spikes
??? Architecture Decisions
-
Used in:
- API rate limiting (AWS, Stripe)
- Network shaping
-
Config knobs:
- Rate (r) ? steady throughput
- Bucket size (b) ? burst capacity
-
Storage:
- In-memory (Redis for distributed systems)
?? Signals / When to Use
Use Token Bucket when:
- Traffic is bursty
- You want graceful throttling
- UX matters (don�t abruptly drop requests)
?? FAANG Interview Q&A
Q1: Why token bucket allows bursts? ?? Because tokens accumulate when idle ? used later.
Q2: What happens when tokens run out? ?? Requests are throttled or delayed.
Q3: How to implement distributed rate limiting? ?? Centralized store (Redis) for token count.
?? Memory Script (Token Bucket)
?? �Token Bucket = Save tokens ? Burst allowed ? Flexible�
?? Leaky Bucket (Smooth / Strict Control)
?? Core Idea
Queue fills ? fixed rate output ?? Incoming bursts are smoothed
?? Key Properties
- Fixed output rate
- Queue (buffer) holds packets
- Overflow ? packet drop
? Pros
- Smooth, predictable traffic
- Simple logic
- Prevents spikes
? Cons
- No burst support
- Packet loss if overloaded
??? Architecture Decisions
-
Used in:
- Network traffic shaping
- VoIP / real-time systems
-
Config knobs:
- Output rate (constant)
- Queue size (buffer capacity)
?? Signals / When to Use
Use Leaky Bucket when:
- Need constant rate output
- Real-time systems (VoIP, streaming)
- Want to avoid spikes at all costs
?? FAANG Interview Q&A
Q1: Why does leaky bucket drop packets? ?? Fixed output ? overflow when input > capacity.
Q2: Difference from token bucket in one line? ?? Token = burst allowed, Leaky = burst removed.
Q3: Why used in VoIP? ?? Ensures steady bandwidth ? smooth audio.
?? Memory Script (Leaky Bucket)
?? �Leaky Bucket = Fixed drain ? Smooth output ? Drops overflow�
?? Direct Comparison (High Signal)
| Feature | Token Bucket (Burst) | Leaky Bucket (Smooth) |
|---|---|---|
| Traffic Handling | Burst allowed | Burst removed |
| Output Rate | Variable | Constant |
| Buffer | Tokens | Queue |
| Overflow | Delay/Throttle | Drop packets |
| Flexibility | High | Low |
| Use Case | APIs, streaming | VoIP, networking |
?? Architecture Decision Rule (FAANG Shortcut)
?? Ask:
1. Do you want to allow bursts?
- YES ? Token Bucket
- NO ? Leaky Bucket
2. Need smooth constant rate?
- YES ? Leaky Bucket
3. User experience sensitive?
- YES ? Token Bucket
?? Advanced Insights (IMPORTANT)
?? Real systems combine both
- Token Bucket ? rate limiting
- Leaky Bucket ? traffic shaping downstream
?? Distributed System Hint
- Token bucket + Redis ? global API rate limiting
- Leaky bucket ? network-level QoS
?? Final 10-sec Brain Hack
?? �Token = Save ? Burst ?? Leaky = Drain ? Smooth�