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
- What is Amazon RDS, and what does it manage for you versus self-managed databases?Amazon RDS is AWS managed relational database service.
- What database engines does RDS support?RDS supports multiple relational engines, including PostgreSQL, MySQL, MariaDB, Oracle, SQL Server, and Db2.
- 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.
- 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…
- 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…
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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…
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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…
- 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
- 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.
- 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.
- 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.
- 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.
- 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.
- What are the SQL isolation levels, and what anomalies does each prevent?Isolation levels define what concurrent transactions are allowed to see.
- 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…
- What is a deadlock, and how do databases detect and resolve them?A deadlock occurs when transactions wait on each other in a cycle.
- What is the difference between OLTP and OLAP workloads?OLTP workloads serve many small, concurrent transactions with low latency and strong correctness.
- What is database normalisation, and when would you denormalise?Normalization reduces duplication and update anomalies by modeling entities in separate related tables.
- 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.
- What is the difference between DELETE, TRUNCATE, and DROP?DELETE removes selected rows, usually with a WHERE clause.
- What is the difference between an INNER JOIN and a LEFT JOIN?An INNER JOIN returns only matching rows from both tables.
- What is a transaction, and what do the ACID properties mean?A transaction is an all-or-nothing unit of work.
- 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.
- 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.
- 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.
- 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.
- What is schema migration, and how do you run migrations safely in production?Schema migration is a controlled change to database structure or data.
- 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,…
- 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.
- 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.
- What is ElastiCache, and what does it manage?ElastiCache is AWS managed in-memory caching for Valkey, Redis OSS, and Memcached.
- 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.
- 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.
- 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.
- 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,…
- 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.
- 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,…
- 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…
- 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.
- 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.
- 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
- What are Redis eviction policies (e.g., LRU, LFU, volatile vs allkeys)?Redis eviction policies decide what Redis removes when maxmemory is reached.
- 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.
- What is a TTL, and how do you choose one for cached data?TTL is the expiration time for a key.
- 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.
- 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.
- 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.
- 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.
- 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.
- What is the difference between Redis Sentinel and Redis Cluster?Sentinel provides failover for one primary dataset without sharding.
- 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.
- What is a cache hit ratio, and how do you improve it?Cache hit ratio is hits divided by total lookups.
- 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…
- 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.
- 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.
- 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.
- 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.
- 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.
- 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.
- 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…
- 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.
- 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…
- What is read-your-writes consistency, and how can caching break it?Read-your-writes means a user sees their own update immediately.
- 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,…
- 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.
- 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.
- 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.
- 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,…
- 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.
- 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.
- 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.
- 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.
- 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…
- 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.
- 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.