Katkat

Backend Fundamentals Deep Dive: MySQL Internals, Redis, and the HTTP/HTTPS Request Lifecycle

ByteDanceBackend Engineer · Technical Screen

Last updated

This problem tests your depth in database durability mechanisms, caching strategies for consistency, and the network-level steps involved in secure HTTP request handling.

Backend Fundamentals: The Lifecycle of a Data Write

Imagine a high-traffic e-commerce service where a user updates their account profile via a secure HTTPS POST request. The service uses an Nginx load balancer, a Redis cache, and a MySQL (InnoDB) database.

Task 1: Database Durability

Explain how MySQL InnoDB ensures ACID properties during a row update. Specifically, trace the interaction between the Buffer Pool, the Redo Log (WAL), and the Undo Log. How does the system guarantee that the transaction is persistent even if the process crashes immediately after the commit?

Task 2: Caching Strategy

To reduce database load, the system uses a 'Cache-Aside' pattern (Lazy Loading). Describe a potential race condition where the cache becomes inconsistent with the database during a concurrent read-update scenario. How would you modify the update sequence to minimize this window of inconsistency?

Task 3: HTTP/HTTPS Lifecycle

Describe the full lifecycle of the user's request. Start from the client initiating a TLS handshake to the point where the server returns a 200 OK. Mention the roles of the TCP 3-way handshake, the TLS negotiation (key exchange), and how the server identifies the persistent connection status (Keep-Alive).

Constraints & Requirements

  • Provide a concise architectural flow for the data consistency mechanism.
  • Explain the trade-offs of using innodb_flush_log_at_trx_commit = 1 vs 2.
  • Discuss why a simple cache.delete() after a database update is not perfectly thread-safe.

Hints

Hint 1

Consider how the WAL (Write-Ahead Logging) protocol allows InnoDB to defer physical disk writes while maintaining durability guarantees.

Hint 2

Think about the sequence of events: if you update the database then delete the cache, what happens if a concurrent read brings 'stale' data into the cache in between?

Hint 3

For the TLS handshake, remember that the client and server exchange random numbers and public keys to establish a symmetric session key for the remainder of the encrypted communication.

Follow-up questions

  • What happens to the Redo Log if the transaction is rolled back by the user? How does the Undo Log participate in this process?
  • If your Redis instance hits the `maxmemory` limit, what are the implications of choosing an LRU (Least Recently Used) eviction policy versus LFU (Least Frequently Used)?
  • How does HTTP/2 header compression (HPACK) and multiplexing change the way we think about the request lifecycle compared to HTTP/1.1?