What is a rate limiter?
A system that restricts the number of requests a user or service can make within a time window.
Difference between a sliding window and a fixed window?
fixed: simpler, allows bursts at boundaries
sliding: more accurate, prevents bursts but slightly more expensive
What is the data structure for rate limiter?
HashMap + Queue (timestamps per user)
How to scale rate limiter?
User Redis (shared state), load balancing, consistent hashing
What is an event deduplicator?
A system that ensures each event is processed only once.
Core data structure for deduplicator?
HashSet or HashMap for O(1) lookup
What is the biggest issue for an event deduplicator?
unbounded memory growth
What is the solution to memory issue for deduplicator?
TTL (time based expiration) + cleanup
How do we optimize a deduplicator for large scale?
Bloom filter (less memory, allows false positives)
What is TTL?
a numerical value in network packets (IP) or DNS records that dictates how long data should exist or be cached before expiring. It prevents data from circulating indefinitely, manages congestion, and ensures timely updates
What is a bloom filter?
a space-efficient, probabilistic data structure used to test set membership, determining if an element is definitely not in a set or possibly in the set
How to design MaxStack in O(1)?
use two stacks
- main stack
- max stack (tracks current max)
What is the difference between horizontal scaling and vertical scaling?
horizontal: add more machines
vertical: upgrade one machine
When would we prefer horizontal scaling?
large-scale systems -> better fault tolerance + scalability
What is a load balancer?
distributes incoming traffic across multiple servers
Why is a load balancer needed?
to prevent overload and improve availability
What is caching?
storing frequently accessed data for faster retrieval
What is an example tool for caching?
Redis
Why would we use Redis for caching?
Redis offers low-latency reads and writes, making it particularly suitable for use cases that require a cache
What is the tradeoff of caching?
speed vs data freshness
Difference between SQL vs NoSQL?
SQL: structures, relational
NoSQL: flexible, scalable
When would we use NoSQL?
high throughput, flexible schema (like event logs)
What is an API?
interface for communication between systems
What is the different between HTTP and HTTPS?
HTTPS is encrypted (secure), HTTP is not