KatInterview

Write Path Internals: InnoDB, Cache Consistency, and TLS

System DesignModel answer
HardModel answerSystem Designmysqlredistls

Last updated

Trace a single HTTPS profile update through TLS negotiation, a Redis cache-aside layer, and InnoDB's WAL-based durability guarantees.

The Long Road of a Single Write

A user submits a profile update on a high-traffic platform. The request travels through a load balancer, hits an application server backed by a Redis cache, and lands in a MySQL InnoDB database. Your job is to explain what actually happens at each layer — not at the level of "data goes in, data comes out," but at the level of what guarantees are being made and what can go wrong.

Answer the three sections below. Concrete mechanisms and trade-offs matter more than definitions.


Part 1 — Storage Durability

Trace what InnoDB does internally when the application executes:

UPDATE users SET display_name = 'Alice' WHERE id = 42;
COMMIT;

Specifically, walk through the roles of the Buffer Pool, the Redo Log (WAL), and the Undo Log. Explain why the committed change survives a process crash that happens the instant after the client receives the success response.

Also compare the durability and performance implications of setting innodb_flush_log_at_trx_commit to 1 versus 2.


Part 2 — Cache Consistency

The service uses a cache-aside (lazy-loading) pattern with Redis. The standard write sequence is:

  1. Write the new value to the database.
  2. Delete the cache key.

Describe a concrete race condition in which a concurrent read repopulates the cache with a stale value after the delete has already run. Then propose at least two strategies that reduce or eliminate this inconsistency window, and explain the trade-offs of each.

Why is a simple cache.delete() after a database commit not fully thread-safe, even when executed correctly?


Part 3 — Secure Request Lifecycle

Walk through the complete lifecycle of the HTTPS POST request, from the moment the client opens a connection to the moment the server sends back 200 OK. Cover:

  • The TCP 3-way handshake and what it establishes
  • The TLS 1.3 handshake: what each side sends, how the session key is derived, and what role the server certificate plays
  • How the server signals whether the connection will be kept alive for future requests

Where relevant, call out how TLS 1.3 differs from TLS 1.2 in terms of round trips and forward secrecy.


What a strong answer looks like

  • Part 1: a step-by-step trace that names specific InnoDB structures, explains crash recovery in three phases, and gives a concrete recommendation on the flush setting with justification.
  • Part 2: a timeline that shows the exact interleaving that produces a stale cache hit, at least two mitigation strategies with trade-offs, and a short code sketch of the safest practical approach.
  • Part 3: a sequential walkthrough that distinguishes authentication from key exchange, states the RTT cost of each phase, and notes what Keep-Alive / Connection: keep-alive headers communicate.

Hints

Hint 1

For Part 1, ask yourself: what exactly has been written to durable storage at the moment the client sees 'commit successful'? The data page in the Buffer Pool is almost certainly still dirty — so what is guaranteeing durability?

Hint 2

For Part 2, draw out a timeline with two threads. The stale-repopulation race requires the read thread to fetch from the DB *before* the write commits but to write to the cache *after* the delete. That ordering is the key insight — then ask what tools can prevent or bound it.

Hint 3

For Part 3, separate the two jobs TLS has to do: prove the server is who it claims to be, and agree on a secret no eavesdropper can recover. In TLS 1.3 these are handled by different mechanisms — the certificate handles the first, ECDHE handles the second. Keep-Alive is an HTTP-layer concern layered on top of the already-established TLS connection.