Database & Caching Interview Questions for Cloud Engineers
State is the hardest part of cloud architecture. Interviewers want to know if you understand consistency, availability, and partition tolerance.
1. Read Replicas vs Sharding
Read Replicas: One primary DB for writes, multiple copies for reads. Solves read-heavy bottlenecks.
Sharding: Partitioning data across multiple DB servers based on a shard key. Solves write-heavy bottlenecks and massive storage needs.
2. What is an eviction policy in Redis?
When Redis reaches its memory limit, it uses an eviction policy (like \allkeys-lru\ or \volatile-lru\) to decide which keys to delete to make room for new data.
3. Explain ACID properties.
- Atomicity: All parts of a transaction succeed, or none do.
- Consistency: The database remains in a valid state before and after the transaction.
- Isolation: Concurrent transactions don't interfere with each other.
- Durability: Committed data is saved permanently, even after a crash.
4. Explain the CAP theorem.
In a distributed data store, you can only guarantee two out of three: Consistency, Availability, and Partition Tolerance. Since network partitions (P) are inevitable, systems must choose between Consistency (CP) and Availability (AP).
5. What is the difference between RDBMS and NoSQL?
RDBMS: Relational, schema-enforced, uses SQL, ACID compliant, scales vertically.
NoSQL: Non-relational, flexible schema, BASE compliant, scales horizontally natively.
6. What is a Database Index?
An index is a data structure (often a B-Tree) that improves the speed of data retrieval operations on a database table at the cost of additional writes and storage space.
7. How does Redis differ from Memcached?
Redis supports complex data structures (Lists, Sets, Hashes), persistence to disk, replication, and Pub/Sub. Memcached is a simpler, pure in-memory key-value store optimized purely for caching strings.
8. What is Database Connection Pooling?
A cache of database connections maintained so that they can be reused. Opening a new DB connection is expensive; pooling improves application performance by reusing existing connections.
9. What is Eventual Consistency?
A consistency model used in distributed systems where, given enough time without new updates, all replicas will eventually converge to the same value (e.g., DNS, DynamoDB).
10. How do you prevent Cache Stampede?
A cache stampede happens when a popular cache key expires, and thousands of concurrent requests hit the database simultaneously. Solutions: adding jitter to expiration times, or using a mutex lock to allow only one request to rebuild the cache.
11. What is the N+1 Query Problem?
An ORM anti-pattern where a query fetches a list of N items, and then N additional queries are executed to fetch related data for each item. Fixed using eager loading (SQL JOINs).
12. Explain Active-Active vs Active-Passive replication.
Active-Active: Multiple nodes can accept writes, requiring complex conflict resolution.
Active-Passive: Only one node accepts writes, replicating to a standby node which takes over if the primary fails.
13. What is a materialized view?
Unlike a standard view (which runs the query every time), a materialized view stores the result of a query physically on disk, offering much faster read performance for complex aggregations, at the cost of data freshness.
14. What are the common caching strategies?
- Cache-Aside (Lazy Loading): App checks cache, if miss, checks DB, updates cache.
- Write-Through: App writes to cache and DB simultaneously.
- Write-Behind: App writes to cache, and an async process writes to DB later.
15. What is a cache miss vs cache hit?
A cache hit occurs when requested data is found in the cache. A cache miss occurs when it is not, requiring the app to fetch it from the slower underlying database.
16. Explain Database Normalization vs Denormalization.
Normalization: Organizing data to reduce redundancy and improve data integrity (using foreign keys).
Denormalization: Adding redundant data to one or more tables to avoid costly JOINs and speed up read performance.
17. What is a Bloom Filter?
A space-efficient probabilistic data structure used to test whether an element is a member of a set. It can definitively say "not in set" but only "possibly in set". Used to avoid expensive DB lookups for non-existent keys.
18. How do you handle schema migrations without downtime?
Using the Expand and Contract pattern: Add the new column (Expand), start writing to both, backfill old data, change reads to use the new column, then drop the old column (Contract).
19. What is a Time-Series Database (TSDB)?
A database optimized for storing and serving time series data (data points indexed by time), commonly used for monitoring metrics (e.g., Prometheus, InfluxDB).
20. What is the "Thundering Herd" problem?
When a large number of processes waiting for an event are woken up simultaneously when the event occurs, overwhelming the system. Mitigated via randomized backoffs or queuing mechanisms.




