TRT
Sign in
mediumCoredesign

Explain the Dual-Write Problem when updating a database and publishing to Kafka. How do the Transactional Outbox pattern, Kafka partition keys (`acks=all`.

Walk through the failure modes of sequential DB + Kafka writes, compare Polling (`FOR UPDATE SKIP LOCKED`) vs WAL CDC (Debezium) outbox relays, explain Kafka ISR durability (`acks=all` + `min.insync.replicas=2`), and design an `Idempotency-Key` state machine.

TRT practice prompt — not a verified question from a named employer.

The Runtime Theory Team2 min read

A strong answer

A strong candidate frames Explain the Dual-Write Problem when updating a database and publishing to Kafka. How do the Transactional Outbox pattern, Kafka partition keys (acks=all. around the exact memory layout, compiler semantics, and hardware execution model covered in [Kafka Partitioned Logs, Consumer Rebalance, the Transactional Outbox, and Idempotent Consumers]. Walk through the failure modes of sequential DB + Kafka writes, compare Polling (FOR UPDATE SKIP LOCKED) vs WAL CDC (Debezium) outbox relays, explain Kafka ISR durability (acks=all + min.insync.replicas=2), and design an Idempotency-Key state machine.

In your checkout service, createOrder() runs await db.query('INSERT INTO orders ...') and then on the very next line runs await kafkaProducer.send({ topic: 'orders', value: order }). Everything passes QA, but in production: (1) Once a week, a pod crashes or hits a network timeout after INSERT INTO orders commits to PostgreSQL but before kafkaProducer.send() succeeds—leaving the order paid in the database but never shipped! (2) Even worse, someone reverses the order (kafkaProducer.send() first, then INSERT INTO orders), and when the DB transaction rolls back on a constraint error, downstream services have already shipped an order that doesn't exist in the database!

When engineers encounter this bottleneck in production, a surface-level API description rarely explains what went wrong. In real workloads, every line of code executes against concrete hardware constraints: fixed-width memory cells, CPU cache lines, kernel descriptor tables, network socket buffers, or accelerator memory buses. Without a clear mental model of Kafka Partitioned Append-Only Logs, the Dual-Write Problem, Transactional Outbox, and Idempotent Consumers, debugging degrades into guesswork—tuning timeouts, adding retries, or scaling instances blindly while the underlying architectural flaw remains untouched.

In a production interview, always connect the specification rule to its concrete runtime consequence: state what lives on the stack versus the heap or static storage segment, how the compiler or operating system validates alignments, lifetimes, and error codes, and what happens under adversarial or boundary inputs (such as zero-length buffers, integer overflow, concurrent mutation, or partial I/O). Backing your explanation with a small trace of register/memory state transitions immediately separates senior systems engineers from candidates who only memorized syntax.

What the interviewer is listening for

  • Mastery of core invariant: Eliminate the Dual-Write Problem between databases and message brokers using the Transactional Outbox pattern (SKIP LOCKED or WAL CDC).
  • Mastery of core invariant: Guarantee strict per-entity FIFO ordering and zero-loss broker durability using Kafka Partition Keys, acks=all, and min.insync.replicas=2.
  • Mastery of core invariant: Achieve Effectively-Once end-to-end processing by combining At-Least-Once outbox/broker delivery with an ACID Idempotent Consumer table.
  • Hardware and ABI awareness: Explaining how sizes, alignments, calling conventions, or kernel boundaries behave on real 64-bit targets rather than relying on implementation-defined assumptions.
  • Defensive engineering: Naming the exact compiler flags (-Wall -Wextra -Werror), static analyzers, or runtime sanitizers (-fsanitize=address,undefined,thread) that verify correctness in CI.

Common mistakes

  • Explaining only surface syntax without tracing the underlying memory addresses, ownership lifetime, or kernel/user-space state transitions.
  • Assuming undefined behavior (such as signed overflow, uninitialized reads, strict-aliasing violations, or dangling pointers) will "just work" because it passed an unoptimized -O0 debug build.
  • Ignoring return codes, partial reads/writes, alignment padding, or cleanup paths when an allocation or syscall fails midway through a function.

This answer walks

Practice follow-ups

  1. 01What happens in Kafka if a producer sets `acks=all` on a topic with `replication.factor=3`, but leaves `min.insync.replicas=1` and the leader broker's disk dies immediately after acknowledging a.
  2. 02When polling an `outbox_events` table in PostgreSQL with 4 relay worker pods, how does `SELECT ... FROM outbox_events WHERE status = 'PENDING' ORDER BY id LIMIT 100 FOR UPDATE SKIP LOCKED` prevent.

Not started

Sign in to save your learning progress.

Sign in to save