Interview questions › Databases & Caching

Databases & Caching interview questions & answers

100 Databases & Caching interview questions, from basic to advanced. Each links to a full answer page with a concise spoken answer, a technical explanation, and a hands-on example.

Tip: paste the job description + your resume into our free resume checker to see which of these skills the role actually requires.

Basic questions

  1. What is Amazon RDS, and what does it manage for you versus self-managed databases?
    Amazon RDS is AWS managed relational database service.
  2. What database engines does RDS support?
    RDS supports multiple relational engines, including PostgreSQL, MySQL, MariaDB, Oracle, SQL Server, and Db2.
  3. What is the difference between RDS and Aurora?
    RDS is the managed service umbrella for standard database engines; Aurora is AWS cloud-native relational engine compatible with MySQL and PostgreSQL.
  4. What is Multi-AZ in RDS, and how does automatic failover work?
    RDS Multi-AZ is a high-availability deployment where RDS maintains a standby or alternate writer in another Availability Zone and automatically fails over when the…
  5. How long does an RDS Multi-AZ failover typically take, and what triggers it?
    RDS Multi-AZ is a high-availability deployment where RDS maintains a standby or alternate writer in another Availability Zone and automatically fails over when the…
  6. What is the difference between Multi-AZ and a read replica?
    Multi-AZ protects the writer for HA and failover; read replicas are readable copies used for read scaling, reporting, migration, and DR.
  7. When would you use a read replica, and can it become a standalone database?
    Multi-AZ protects the writer for HA and failover; read replicas are readable copies used for read scaling, reporting, migration, and DR.
  8. Can a read replica be in a different region, and why would you do that?
    Multi-AZ protects the writer for HA and failover; read replicas are readable copies used for read scaling, reporting, migration, and DR.
  9. What is the difference between automated backups and manual snapshots in RDS?
    Automated backups are retained for a configured window and support point-in-time recovery.
  10. What is the backup retention period, and what is point-in-time recovery?
    Automated backups are retained for a configured window and support point-in-time recovery.
  11. How does point-in-time recovery work under the hood (snapshots plus transaction logs)?
    Automated backups are retained for a configured window and support point-in-time recovery.
  12. What is an RDS parameter group, and give an example of a parameter you would tune?
    An RDS parameter group is a managed set of database engine configuration parameters.
  13. What is an RDS option group?
    An RDS option group enables engine-specific optional capabilities that are not simple parameter settings, especially for Oracle, SQL Server, and some MySQL/MariaDB…
  14. How do you perform a major version upgrade of RDS with minimal downtime?
    For a major RDS upgrade, I avoid untested in-place changes on critical systems.
  15. Walk me through a safe RDS PostgreSQL/MySQL upgrade with a rollback plan.
    For a major RDS upgrade, I avoid untested in-place changes on critical systems.
  16. What is a blue-green deployment for RDS, and how does it reduce upgrade risk?
    For a major RDS upgrade, I avoid untested in-place changes on critical systems.
  17. How do you test that an application is compatible before a database major upgrade?
    For a major RDS upgrade, I avoid untested in-place changes on critical systems.
  18. How do you encrypt an RDS instance at rest, and can you encrypt an existing unencrypted one?
    New RDS instances should be encrypted at creation with KMS.
  19. How do you enforce encryption in transit (SSL/TLS) to RDS?
    Encryption in transit is enforced by requiring TLS from clients and configuring the engine to reject non-TLS connections where supported.
  20. How do you rotate database credentials, and how does Secrets Manager help?
    I rotate DB credentials through AWS Secrets Manager or an equivalent secrets system.
  21. How do you monitor RDS performance (CloudWatch, Performance Insights, Enhanced Monitoring)?
    RDS performance monitoring should combine CloudWatch, Performance Insights, Enhanced Monitoring, database-native views, logs, and application SLOs.
  22. What is Performance Insights, and what does it help you find?
    RDS performance monitoring should combine CloudWatch, Performance Insights, Enhanced Monitoring, database-native views, logs, and application SLOs.
  23. What are common causes of high RDS CPU, and how do you investigate?
    RDS performance monitoring should combine CloudWatch, Performance Insights, Enhanced Monitoring, database-native views, logs, and application SLOs.
  24. How do you scale an RDS database vertically and what is the downtime impact?
    Vertical scaling changes the RDS DB instance class to add CPU, memory, or network capacity.
  25. How do you scale reads versus writes on a relational database?
    Reads can be scaled with replicas, caching, materialized views, query optimization, denormalized read models, and analytics offload.
  26. What is connection pooling, and why does it matter for RDS (e.g., RDS Proxy)?
    Connection pooling reuses a bounded set of database connections and prevents unbounded clients from exhausting the database.
  27. What is RDS Proxy, and what problem does it solve?
    Connection pooling reuses a bounded set of database connections and prevents unbounded clients from exhausting the database.
  28. What is the difference between PostgreSQL and MySQL from an operator's view?
    PostgreSQL and MySQL differ operationally in storage behavior, MVCC implementation, replication, indexing, planner behavior, extensions, and maintenance.
  29. What is MVCC, and how does PostgreSQL implement it?
    PostgreSQL and MySQL differ operationally in storage behavior, MVCC implementation, replication, indexing, planner behavior, extensions, and maintenance.
  30. What is VACUUM in PostgreSQL, and why is autovacuum important?
    PostgreSQL and MySQL differ operationally in storage behavior, MVCC implementation, replication, indexing, planner behavior, extensions, and maintenance.
  31. What is transaction wraparound in PostgreSQL, and why is it dangerous?
    PostgreSQL and MySQL differ operationally in storage behavior, MVCC implementation, replication, indexing, planner behavior, extensions, and maintenance.
  32. What is the difference between a clustered and a non-clustered index?
    A clustered index controls or reflects the physical row order in engines that support it; a non-clustered index is a separate lookup structure that points to the…
  33. What is an index, and what are the trade-offs of adding one?
    An index is a structure that lets the database find rows without scanning the full table.

Intermediate questions

  1. How do you decide which columns to index?
    I decide indexes from real workload evidence: WHERE predicates, JOIN keys, ORDER BY, GROUP BY, uniqueness rules, and top expensive queries.
  2. What is a composite index, and does column order matter?
    A composite index covers multiple columns, and column order matters because the optimizer can use the leftmost prefix most effectively.
  3. What is a covering index?
    A covering index includes all columns needed by a query so the database can answer from the index without reading the base table, when visibility rules allow it.
  4. How do you find and fix a slow query (EXPLAIN / EXPLAIN ANALYZE)?
    I find a slow query from traces, slow logs, Performance Insights, or pg_stat_statements, then inspect it with EXPLAIN or EXPLAIN ANALYZE.
  5. What does an execution plan tell you, and what is a sequential scan versus an index scan?
    An execution plan shows how the database will access, join, sort, and filter data.
  6. What are the SQL isolation levels, and what anomalies does each prevent?
    Isolation levels define what concurrent transactions are allowed to see.
  7. What is the difference between a dirty read, non-repeatable read, and phantom read?
    A dirty read sees uncommitted data, a non-repeatable read sees the same row change between reads in one transaction, and a phantom read sees the result set of a…
  8. What is a deadlock, and how do databases detect and resolve them?
    A deadlock occurs when transactions wait on each other in a cycle.
  9. What is the difference between OLTP and OLAP workloads?
    OLTP workloads serve many small, concurrent transactions with low latency and strong correctness.
  10. What is database normalisation, and when would you denormalise?
    Normalization reduces duplication and update anomalies by modeling entities in separate related tables.
  11. What is the difference between a primary key, a unique key, and a foreign key?
    A primary key uniquely identifies each row and cannot be null.
  12. What is the difference between DELETE, TRUNCATE, and DROP?
    DELETE removes selected rows, usually with a WHERE clause.
  13. What is the difference between an INNER JOIN and a LEFT JOIN?
    An INNER JOIN returns only matching rows from both tables.
  14. What is a transaction, and what do the ACID properties mean?
    A transaction is an all-or-nothing unit of work.
  15. What is WAL (write-ahead logging), and how does it support durability and replication?
    WAL, or write-ahead logging, records changes durably before data pages are considered committed.
  16. What is synchronous versus asynchronous replication, and the trade-offs?
    Synchronous replication waits for a replica acknowledgement before commit returns, reducing data-loss risk but increasing latency.
  17. How do you migrate a database with near-zero downtime (e.g., using DMS or logical replication)?
    Near-zero downtime migration uses initial load plus ongoing change replication, then a short write drain and controlled cutover.
  18. What is AWS DMS, and when would you use it?
    AWS DMS is a managed migration and replication service that can perform full loads and change data capture between supported sources and targets.
  19. What is schema migration, and how do you run migrations safely in production?
    Schema migration is a controlled change to database structure or data.
  20. How do you make a schema change backward compatible during a rolling deploy?
    For rolling deploys, I make schema changes backward compatible with expand-and-contract: add new structures first, deploy code that supports old and new, backfill,…
  21. Why are some ALTER TABLE operations dangerous on a large table, and how do you mitigate?
    Large ALTER TABLE operations are dangerous because they can lock tables, rewrite data, generate huge WAL/binlogs, increase replica lag, and exhaust storage.
  22. What is connection exhaustion, and how do you prevent it?
    Connection pooling reuses a bounded set of database connections and prevents unbounded clients from exhausting the database.
  23. What is ElastiCache, and what does it manage?
    ElastiCache is AWS managed in-memory caching for Valkey, Redis OSS, and Memcached.
  24. What is the difference between ElastiCache Redis and Memcached?
    Redis or Valkey supports rich data structures, persistence-related features, replication, clustering, Lua, streams, and pub/sub.
  25. What is Redis, and what core data types does it support?
    Redis is an in-memory data structure server used for caching, counters, queues, rate limits, sessions, and coordination.
  26. What is Valkey, and why did the community fork it from Redis?
    Valkey is an open-source Redis-compatible datastore forked after Redis changed its license.
  27. Walk me through your ElastiCache Redis to Valkey migration: motivation, plan, and validation.
    A Redis to Valkey migration should be driven by support, licensing, cost, or platform-standardization goals, then executed through inventory, compatibility testing,…
  28. How do you migrate from Redis to Valkey with minimal downtime?
    For minimal downtime Redis to Valkey migration, I first classify whether the cache is disposable or authoritative.
  29. How is Valkey wire-compatible with Redis, and what risks remain in a migration?
    Valkey wire compatibility means normal Redis clients and protocol-level commands usually work, but risks remain around version differences, modules, Lua scripts,…
  30. What are common caching patterns (cache-aside, read-through, write-through, write-behind)?
    Cache-aside loads from the DB on miss, read-through lets the cache layer load, write-through writes cache and DB synchronously, and write-behind writes to cache first…
  31. What is cache-aside (lazy loading), and what are its failure modes?
    Cache-aside means the app checks cache first, reads the database on miss, writes the value to cache with TTL, and returns it.
  32. What is a cache stampede / thundering herd, and how do you prevent it?
    A cache stampede happens when many clients miss the same hot key at once and all hit the backend.
  33. What is cache invalidation, and why is it hard?
    Cache invalidation is deciding when cached data is no longer correct and removing or refreshing it.

Advanced questions

  1. What are Redis eviction policies (e.g., LRU, LFU, volatile vs allkeys)?
    Redis eviction policies decide what Redis removes when maxmemory is reached.
  2. What happens when Redis reaches maxmemory?
    When Redis reaches maxmemory, it either evicts eligible keys based on policy or rejects memory-growing writes if no key can be evicted.
  3. What is a TTL, and how do you choose one for cached data?
    TTL is the expiration time for a key.
  4. What is the difference between Redis persistence options RDB and AOF?
    RDB creates point-in-time snapshot files, while AOF appends write commands to a log for replay.
  5. What are the durability trade-offs between RDB snapshots and AOF?
    RDB has lower overhead and faster compact backups but can lose changes after the last snapshot.
  6. What is Redis replication, and how does a replica stay in sync?
    Redis replication copies data from a primary to replicas through initial synchronization and ongoing write streams.
  7. What is Redis Sentinel, and what does it provide?
    Redis Sentinel monitors a primary-replica deployment, detects primary failure, elects a new primary, and provides discovery.
  8. What is Redis Cluster, and how does sharding with hash slots work?
    Redis Cluster shards the keyspace across 16,384 hash slots owned by primary nodes, with replicas for HA.
  9. What is the difference between Redis Sentinel and Redis Cluster?
    Sentinel provides failover for one primary dataset without sharding.
  10. How does ElastiCache provide high availability and automatic failover?
    ElastiCache provides HA through replication groups, Multi-AZ replicas, node health monitoring, automatic failover, and endpoint updates.
  11. What is a cache hit ratio, and how do you improve it?
    Cache hit ratio is hits divided by total lookups.
  12. How do you monitor Redis/ElastiCache (evictions, memory, latency, hit ratio)?
    I monitor Redis or ElastiCache with hit ratio, latency, CPU, memory, evictions, fragmentation, connections, rejected connections, replication lag, slowlog, command…
  13. What is the impact of a large key or hot key in Redis, and how do you handle it?
    A large key increases memory, network, replication, and latency cost; a hot key concentrates too much traffic on one key or shard.
  14. Why are some Redis commands (KEYS, FLUSHALL) dangerous in production?
    KEYS can block Redis by scanning the full keyspace, and FLUSHALL can delete the entire cache or datastore.
  15. What is pipelining in Redis, and how does it improve throughput?
    Pipelining sends multiple commands before waiting for replies, reducing network round trips and increasing throughput.
  16. What is the difference between Redis as a cache and Redis as a primary datastore?
    Redis as a cache is rebuildable from another source of truth.
  17. How would you use Redis for rate limiting?
    For rate limiting, Redis commonly uses atomic counters with INCR and EXPIRE for fixed windows or sorted sets for sliding windows.
  18. How would you use Redis for distributed locking, and what are the caveats?
    Redis distributed locks commonly use SET key value NX PX ttl with a unique token and compare-and-delete release.
  19. How do you secure Redis (AUTH, TLS, network isolation, no public exposure)?
    Redis security starts with private networking, no public exposure, security groups, TLS, AUTH or ACLs, least-privilege users, secret rotation, and blocking dangerous…
  20. What is the difference between strong and eventual consistency, and where does caching sit?
    Strong consistency means reads reflect the latest committed write; eventual consistency means replicas or caches can be temporarily stale.
  21. How do you keep a cache and database consistent?
    I keep cache and DB consistent by treating the DB as source of truth, using TTLs, invalidating after commits, versioning keys, and using outbox-driven invalidation so…
  22. What is read-your-writes consistency, and how can caching break it?
    Read-your-writes means a user sees their own update immediately.
  23. How would you design caching for a read-heavy microservice?
    For a read-heavy microservice, I cache hot, expensive, safe-to-stale data using clear key naming, TTL plus jitter, explicit invalidation, request coalescing, warming,…
  24. How do you decide what to cache and what not to cache?
    I cache data that is frequently read, expensive to fetch or compute, reasonably small, and tolerant of staleness.
  25. How do you handle cache warming after a restart or failover?
    Cache warming preloads hot keys after restart, failover, or new cluster creation so user traffic does not create a cold-cache miss storm.
  26. What is the blast radius of a cache outage, and how do you make the app degrade gracefully?
    A cache outage can cause anything from minor latency to full outage.
  27. How do you size an ElastiCache cluster (memory, nodes, shards)?
    I size ElastiCache from working-set memory, key/value overhead, fragmentation, CPU, network, connection count, replica needs, shard distribution, failover headroom,…
  28. What backup and restore options exist for ElastiCache Redis?
    ElastiCache Redis or Valkey backup options include automatic backups, manual snapshots, and snapshot restore into a new cluster where supported.
  29. How do you test a Redis or database failover without impacting users?
    I test database or Redis failover through staging and approved game days, measuring application recovery, reconnect behavior, error rate, latency, and alerting.
  30. How do you handle connection storms against the cache after a deploy?
    Connection storms happen when many clients reconnect simultaneously after deploy, failover, scaling, or network issues.
  31. What is the difference between a write-through and write-behind cache regarding data loss?
    Write-through updates cache and database synchronously, giving stronger consistency but higher write latency.
  32. How would you debug rising latency on a service that depends on Redis and RDS together?
    To debug latency involving both Redis and RDS, I break the path into cache hit/miss, Redis latency, DB query time, connection wait, and app processing, then correlate…
  33. What recent database or caching change have you made, and what did it improve?
    A strong recent-change answer should describe business driver, risk controls, migration or upgrade plan, validation, rollback, and measured improvement.
  34. How do you plan capacity and storage autoscaling for a growing RDS database?
    For RDS capacity, I plan storage, IOPS, throughput, CPU, memory, connections, WAL/binlog growth, backup/restore time, and data growth.

← All interview topics