Requirements, APIs, data, caching, queues, scaling and trade-offs
Practise these as flashcards. One or two lines each; the ones you miss come back first.
Start freeI begin by clarifying the requirements with the interviewer to understand the core features, constraints, and any non-functional needs. This ensures we're aligned before diving into the design.
A cache is a fast, temporary storage layer that holds frequently accessed data to reduce latency and database load. It's useful because it speeds up responses and improves scalability.
Horizontal scaling means adding more servers or instances to handle increased load, rather than upgrading a single machine. This approach improves reliability and allows systems to grow as needed.
A dead-letter queue is a special queue where messages that can't be processed successfully after several attempts are sent. This helps isolate problematic data and prevents it from blocking the main processing flow.
I'd estimate the number of URLs stored per day, multiply by the average size per record (including code, original URL, and metadata), and project this over the expected retention period. For example, if we store 1 million URLs/day at 200 bytes each, that's about 200MB/day, or roughly 73GB/year.
In cache-aside, the application loads data into the cache on demand and updates the cache after writes. In write-through, all writes go through the cache, which updates both the cache and the database simultaneously, keeping them in sync but potentially increasing write latency.
I'd choose NoSQL when I need to handle large-scale, unstructured, or rapidly changing data, or when horizontal scaling is a priority. For example, storing user activity logs or social feed events is often a good fit for NoSQL.
Eventual consistency means that, after a write, all replicas will eventually reflect the change, but not necessarily immediately. It's acceptable in scenarios where slight delays in data propagation are tolerable, like social media feeds or analytics dashboards.
I design the consumer logic so that processing the same message multiple times has the same effect as processing it once. This often involves using unique request IDs or checking if an operation has already been performed before applying changes.
A load balancer distributes incoming requests across multiple servers, so if one server fails, traffic is redirected to healthy ones. This reduces downtime and helps maintain consistent performance under varying loads.
A circuit breaker is a pattern that detects repeated failures in a service and temporarily blocks requests to prevent further strain. It's important because it helps avoid cascading failures and allows the system to recover gracefully.
Back-pressure is a mechanism where overloaded services signal clients or upstream components to slow down or stop sending requests. It helps prevent resource exhaustion and cascading failures by matching the incoming rate to what the system can handle.