Tutorials Courses Interview Prep (100 Q&A) AI Tools (50) Developer Tools (50) Tracks Pricing Plans Blog & Articles Contact Us
Open-Access Production Interview Prep

Senior & Lead Engineer Interview Mastery Hub

100 real-world, scenario-based architecture & concurrency questions designed for 5–10+ years experienced developers. Free & open for every student and engineer.

100

Real-world Q&As

100%

Scenario-Based

5-10 Yrs

Senior / Lead Depth

5 Stacks

Core Technologies

Showing 20 questions for senior interview preparation

•
MySQL Tuning, Indexing & Concurrency 8-10 Years (Tech Lead) Hard Production Scenario

How does the InnoDB B+Tree Index work internally, and why does Leftmost Prefix Rule dictate composite index column ordering?

Incident Scenario: A query `WHERE status = "active" AND created_at >= "2026-01-01" AND user_id = 500` was doing a full table scan across 30 million rows despite having an index on `(created_at, status, user_id)`.
133 views • Direct Permalink

Why B+Tree Needs Leftmost Prefix Rule

In an InnoDB B+Tree, index keys are sorted lexicographically based on the order of columns defined in the index: (ColA, ColB, ColC).

  • If a query filters on ColB without ColA, the B+Tree root cannot branch because ColB is only sorted within duplicate values of ColA.
  • Range Queries Stop Index Filtering: Once a range operator (>, <, BETWEEN, >=) is evaluated, subsequent columns in the composite index cannot be used for B+Tree traversal.

Fixing the Slow Query

Because created_at used a range operator (>=), placing it first broke index lookups for status and user_id.

Optimal Composite Index Column Order:

  1. Exact equality matches with highest cardinality first: user_id
  2. Equality match: status
  3. Range match last: created_at
ALTER TABLE orders ADD INDEX idx_user_status_created (user_id, status, created_at);

Query execution time drops from 8.5 seconds (full scan) to 0.8 milliseconds (index seek).

Tags: #MySQL #InnoDB #B+Tree #Composite Index #Leftmost Prefix
MySQL Tuning, Indexing & Concurrency 10+ Years (Principal / Architect) Expert Production Scenario

Explain InnoDB Locking Modes: Record Locks, Gap Locks, and Next-Key Locks, and how they prevent Phantom Reads.

Incident Scenario: Under `REPEATABLE READ` isolation level, two concurrent transactions inserting users with IDs between 10 and 20 resulted in lock wait timeouts and deadlocks.
277 views • Direct Permalink

The Three InnoDB Row Lock Types

  1. Record Lock: Locks the physical index record itself (e.g. WHERE id = 5 FOR UPDATE).
  2. Gap Lock: Locks the gap between index records (or before the first / after the last) to prevent other transactions from inserting new rows in that gap.
  3. Next-Key Lock: A combination of a Record Lock on the index record plus a Gap Lock on the gap preceding it.

Why MySQL Uses Next-Key Locks by Default

Under the default REPEATABLE READ isolation level, MySQL uses Next-Key locking to solve the Phantom Read problem (preventing another transaction from inserting a new row that matches your query's range before you commit).

Reducing Lock Contention:

Switching transaction isolation to READ COMMITTED (with binlog_format=ROW) disables Gap Locks except for foreign key constraint checks and duplicate key checks.

Tags: #InnoDB Locks #Gap Locks #Next-Key Locks #Phantom Reads #Transactions
MySQL Tuning, Indexing & Concurrency 5-8 Years (Senior) Hard Production Scenario

How do you optimize deep pagination (`SELECT * ... LIMIT 5000000, 20`) on large tables with 100M rows?

Incident Scenario: An API endpoint paginating through 50 million audit log records timed out (504 Gateway Timeout) when users accessed page 50,000.
187 views • Direct Permalink

Why LIMIT 5000000, 20 is Slow

MySQL must scan, read from disk, and discard all 5,000,000 preceding rows before returning the 20 requested records.

Solution 1: Cursor-Based Pagination (Seek Method) - FASTEST

Instead of offset, filter by the last seen ID:

SELECT * FROM audit_logs
WHERE id < 45000000
ORDER BY id DESC
LIMIT 20;

Direct B+Tree seek, runs in 0.4 milliseconds on any page number.

Solution 2: Deferred Join (Late Row Lookup)

If random page offset jumps are required, use a covering index subquery:

SELECT a.* FROM audit_logs a
JOIN (
    SELECT id FROM audit_logs
    ORDER BY created_at DESC
    LIMIT 5000000, 20
) AS sub ON a.id = sub.id;

The inner subquery scans only the memory-efficient index tree without fetching heavy row columns until the final 20 IDs are found.

Tags: #Pagination #LIMIT OFFSET #Deferred Join #Cursor Pagination
MySQL Tuning, Indexing & Concurrency 5-8 Years (Senior) Hard Production Scenario

How do you interpret MySQL `EXPLAIN ANALYZE` output to diagnose `Using filesort` and `Using temporary`?

Incident Scenario: An analytical query grouping and sorting orders was spilling to disk (`Using temporary; Using filesort`), consuming 100% disk I/O.
505 views • Direct Permalink

Diagnosing EXPLAIN ANALYZE

  • Using filesort: MySQL cannot use an index to satisfy the ORDER BY clause and must perform an extra sorting pass in memory (sort_buffer_size) or on disk.
  • Using temporary: MySQL creates an internal temporary table (in RAM or disk) to hold intermediate results, common with GROUP BY and DISTINCT on non-indexed columns.

Remediation:

  1. Create a composite index covering both the filter and the order:
    CREATE INDEX idx_merchant_created ON orders (merchant_id, created_at DESC);
    
  2. When query runs WHERE merchant_id = 5 ORDER BY created_at DESC, MySQL reads pre-sorted index nodes directly without filesort or temporary tables.
Tags: #EXPLAIN ANALYZE #filesort #Temporary Table #Performance
MySQL Tuning, Indexing & Concurrency 10+ Years (Principal / Architect) Expert Production Scenario

Explain MySQL Table Partitioning (Range, List, Hash) vs. Application-Level Sharding for 1TB+ databases.

Incident Scenario: A financial ledger table is growing by 50 million rows monthly. Queries for current-month records are slowing down.
704 views • Direct Permalink

Range Partitioning by Date

Partitioning splits a single logical table into separate physical files on disk:

ALTER TABLE transactions PARTITION BY RANGE (YEAR(created_at) * 100 + MONTH(created_at)) (
    PARTITION p202601 VALUES LESS THAN (202602),
    PARTITION p202602 VALUES LESS THAN (202603),
    PARTITION p202603 VALUES LESS THAN (202604),
    PARTITION p_future VALUES LESS THAN MAXVALUE
);

Benefits:

  1. Partition Pruning: Queries with WHERE created_at BETWEEN '2026-02-01' AND '2026-02-28' scan ONLY the p202602 physical file.
  2. Instant Purges: Dropping 50 million historical rows takes 0.1 seconds via ALTER TABLE transactions DROP PARTITION p202401; rather than a catastrophic DELETE FROM transactions... holding millions of row locks.
Tags: #Partitioning #Sharding #Range Partition #Big Data
MySQL Tuning, Indexing & Concurrency 8-10 Years (Tech Lead) Hard Production Scenario

How does the InnoDB Buffer Pool manage dirty pages, and how do you size `innodb_buffer_pool_size` for production servers?

Incident Scenario: A dedicated MySQL database server with 128GB RAM was running out of memory because buffer pool and OS page caches were misconfigured.
794 views • Direct Permalink

Sizing innodb_buffer_pool_size

On a dedicated database server, set innodb_buffer_pool_size to 70% - 80% of total system RAM:

  • For 128GB RAM: innodb_buffer_pool_size = 96G
  • Configure multiple buffer pool instances to reduce mutex contention: innodb_buffer_pool_instances = 8
Tags: #Buffer Pool #InnoDB #Memory Sizing #Dirty Pages
MySQL Tuning, Indexing & Concurrency 8-10 Years (Tech Lead) Hard Production Scenario

How do you troubleshoot and fix MySQL Replication Lag in Master-Replica setups?

Incident Scenario: Replica lag jumped to 3,600 seconds on a secondary reader server during nightly report generation.
686 views • Direct Permalink

Key Fixes for Replication Lag

  1. Enable Multi-Threaded Slaves (MTS):
    slave_parallel_workers = 16
    slave_parallel_type = LOGICAL_CLOCK
    
  2. Eliminate Huge Single-Query Writes: Break massive 5-million-row DELETE or UPDATE statements into chunks of 5,000.
  3. Disable Sync Binlog on Replicas: Set sync_binlog = 0 and innodb_flush_log_at_trx_commit = 2 on read replicas.
Tags: #Replication Lag #Multi-Threaded Slave #High Availability
MySQL Tuning, Indexing & Concurrency 5-8 Years (Senior) Medium

What is the difference between Clustered Index and Secondary Index in InnoDB?

Incident Scenario: An interviewer asks why secondary index lookups perform a secondary traversal back to the clustered index (Bookmark Lookup).
239 views • Direct Permalink

Clustered vs Secondary Index

  • Clustered Index: The physical table data rows are stored directly inside the leaf nodes of the Primary Key B+Tree.
  • Secondary Index: Leaf nodes store only the indexed column value and the Primary Key value (not a physical row pointer).
  • To retrieve non-indexed columns, MySQL must perform a Bookmark Lookup (reading secondary index -> extracting PK -> searching Clustered Index).
Tags: #Clustered Index #Secondary Index #InnoDB Internals
MySQL Tuning, Indexing & Concurrency 5-8 Years (Senior) Medium Production Scenario

How does Covering Index eliminate Bookmark Lookups to achieve sub-millisecond query performance?

Incident Scenario: A dashboard query fetching user email and created date was reading millions of rows from disk.
174 views • Direct Permalink

Covering Index (Using index)

When all columns requested in SELECT, WHERE, and ORDER BY exist within the secondary index itself, MySQL retrieves data directly from the index in RAM without touching table row data on disk.

CREATE INDEX idx_users_org_email_date ON users (org_id, email, created_at);

Query: SELECT email, created_at FROM users WHERE org_id = 10; is 100% satisfied by the index.

Tags: #Covering Index #Index Only Scan #Performance
MySQL Tuning, Indexing & Concurrency 8-10 Years (Tech Lead) Hard Production Scenario

Explain the 4 Transaction Isolation Levels in MySQL and the anomalies they prevent (Dirty Read, Non-Repeatable Read, Phantom Read).

Incident Scenario: An accounting team discovered discrepancies in financial balances generated during concurrent ledger updates.
587 views • Direct Permalink

ACID Isolation Levels

Level Dirty Read Non-Repeatable Read Phantom Read Default In
READ UNCOMMITTED Possible Possible Possible -
READ COMMITTED Prevented Possible Possible Postgres / Oracle
REPEATABLE READ Prevented Prevented Prevented (via MVCC/Gap Lock) MySQL InnoDB
SERIALIZABLE Prevented Prevented Prevented Strict Financials
Tags: #Isolation Levels #ACID #Transactions #Concurrency
MySQL Tuning, Indexing & Concurrency 5-8 Years (Senior) Hard Production Scenario

How do you identify and resolve Deadlocks using `SHOW ENGINE INNODB STATUS`?

Incident Scenario: Production logs report MySQL error 1213. You need to extract the exact queries, locks, and transactions involved.
743 views • Direct Permalink

Analyzing LATEST DETECTED DEADLOCK

Run:

SHOW ENGINE INNODB STATUS\G

Look for:

  • (1) TRANSACTION vs (2) TRANSACTION
  • LOCK WAIT statements
  • RECORD LOCKS space id ... lock_mode X
  • Identify which transaction was chosen as the deadlock victim and rolled back based on the lowest number of modified rows.
Tags: #Deadlocks #InnoDB Status #Debugging
MySQL Tuning, Indexing & Concurrency 5-8 Years (Senior) Medium Production Scenario

Why does `SELECT COUNT(*)` on InnoDB scan the entire primary key tree unlike MyISAM?

Incident Scenario: Executing `SELECT COUNT(*) FROM orders` on a 50-million row InnoDB table took 12 seconds.
767 views • Direct Permalink

Why InnoDB Cannot Store an Exact Row Count

Because InnoDB uses MVCC (Multi-Version Concurrency Control), different concurrent transactions see different numbers of visible rows at the exact same moment.

  • MyISAM locked tables and stored a single counter, but did not support transactions.
  • Solution for Large Tables: Use Redis cached counters or query information_schema.TABLES.TABLE_ROWS for approximations.
Tags: #COUNT #InnoDB #MVCC #Performance
MySQL Tuning, Indexing & Concurrency 5-8 Years (Senior) Medium Production Scenario

How do Generated (Virtual & Stored) Columns and Functional Indexes optimize queries in MySQL 8?

Incident Scenario: Searching through a JSON column `details->>"$.customer_code"` was executing full table scans.
633 views • Direct Permalink

Functional Index on JSON Expressions

ALTER TABLE orders ADD INDEX idx_customer_code ((CAST(details->>'$.customer_code' AS CHAR(30))));

MySQL 8 allows indexing expressions directly without needing stored physical columns.

Tags: #MySQL 8 #JSON #Generated Columns #Functional Index
MySQL Tuning, Indexing & Concurrency 8-10 Years (Tech Lead) Hard Production Scenario

How does `innodb_flush_log_at_trx_commit` trade ACID durability for 10x write throughput?

Incident Scenario: A high-speed IoT ingestion pipeline writing 20,000 metrics per second was bottlenecked by disk IOPS.
117 views • Direct Permalink

innodb_flush_log_at_trx_commit Settings

  • 1 (Default / Strict ACID): Redo log is flushed to disk on every single transaction commit. Maximum safety, high disk IOPS.
  • 2: Redo log is written to OS cache on commit and flushed to disk once per second. If OS crashes, at most 1 second of data is lost, but write throughput increases up to 10x.
  • 0: Flushed once per second in memory.
Tags: #ACID #Redo Log #IOPS #Tuning
MySQL Tuning, Indexing & Concurrency 5-8 Years (Senior) Hard Production Scenario

How do you optimize Foreign Key checks and cascading deletes on huge tables without causing lock contention?

Incident Scenario: Deleting a customer record triggered `ON DELETE CASCADE` on 200,000 child records, freezing the database.
656 views • Direct Permalink

Best Practice for High-Scale Systems

Avoid heavy database-level cascading deletes. Instead, perform soft-deletes or chunked background queue deletions:

-- Delete in chunks of 5,000 to prevent long-held row locks
DELETE FROM order_items WHERE order_id = 12345 LIMIT 5000;
Tags: #Foreign Keys #Cascading Delete #Locking
MySQL Tuning, Indexing & Concurrency 8-10 Years (Tech Lead) Hard

What is the purpose of the MySQL Redo Log and Undo Log in Crash Recovery?

Incident Scenario: The server suffered an abrupt power failure during heavy transaction processing. How does MySQL restore consistency upon restart?
422 views • Direct Permalink

Redo Log vs Undo Log

  • Redo Log (Write-Ahead Logging / WAL): Records physical changes to data pages. During crash recovery, MySQL replays the redo log to restore committed transactions that were not yet flushed from RAM to table data files.
  • Undo Log: Records the opposite actions needed to rollback uncommitted transactions active at the time of the crash.
Tags: #Redo Log #Undo Log #Crash Recovery #WAL
MySQL Tuning, Indexing & Concurrency 5-8 Years (Senior) Medium Production Scenario

How does MySQL 8 CTE (Common Table Expressions) and Recursive Queries simplify hierarchical data traversal?

Incident Scenario: Querying an organization tree of managers, subordinates, and department hierarchies.
696 views • Direct Permalink

Recursive CTE Example

WITH RECURSIVE OrgChart AS (
    SELECT id, name, manager_id, 1 as level
    FROM employees WHERE manager_id IS NULL
    UNION ALL
    SELECT e.id, e.name, e.manager_id, o.level + 1
    FROM employees e
    JOIN OrgChart o ON e.manager_id = o.id
)
SELECT * FROM OrgChart ORDER BY level;
Tags: #CTE #Recursive Queries #MySQL 8 #Hierarchical Data
MySQL Tuning, Indexing & Concurrency 5-8 Years (Senior) Medium Production Scenario

How do you optimize `LIKE "%search%"` full string searches on tables with millions of rows without elasticsearch?

Incident Scenario: Product title searches with leading wildcards (`LIKE "%laptop%"`) could not use regular B+Tree indexes.
60 views • Direct Permalink

MySQL FULLTEXT Index with N-Gram Parser

ALTER TABLE products ADD FULLTEXT INDEX ft_title_desc (title, description) WITH PARSER ngram;

-- High performance full text search
SELECT * FROM products
WHERE MATCH(title, description) AGAINST('+laptop +pro' IN BOOLEAN MODE);
Tags: #Fulltext Index #LIKE Search #Performance
MySQL Tuning, Indexing & Concurrency 8-10 Years (Tech Lead) Medium Production Scenario

How do you safely rename a column or drop an index in MySQL production without taking locks?

Incident Scenario: Dropping an unused index on a busy 80M row table caused application write queries to stall.
277 views • Direct Permalink

MySQL 8 Invisible Indexes & Online Drop

  1. Make Index Invisible First:
    ALTER TABLE orders ALTER INDEX idx_old_status INVISIBLE;
    
    Verifies if optimizer or queries degrade without that index.
  2. Drop Online:
    ALTER TABLE orders DROP INDEX idx_old_status, ALGORITHM=INPLACE, LOCK=NONE;
    
Tags: #Online DDL #Index Management #Production Safety
MySQL Tuning, Indexing & Concurrency 10+ Years (Principal / Architect) Expert Production Scenario

How does Group Replication and MySQL InnoDB Cluster achieve High Availability (HA) with zero data loss?

Incident Scenario: Architecting an automated database failover system across 3 availability zones with Paxos consensus.
575 views • Direct Permalink

MySQL InnoDB Cluster Architecture

  1. Group Replication: Uses a Paxos-based consensus protocol where transactions are validated across majority nodes (quorum) before commit.
  2. MySQL Router: Automatically routes incoming read/write traffic to the primary node and read traffic across secondaries.
  3. Automatic Failover: If the primary crashes, the cluster elects a new primary in seconds without human intervention.
Tags: #InnoDB Cluster #Group Replication #High Availability #Paxos