The Real Fullstack

The Dirty Read

The transfer was rolled back. So where did the €9,000 the loan check saw come from?

Ingeniero7 minSimulador de línea de tiempoReto de código
sqlpostgresqlmysqlsql-server

Este reto aún no está traducido al Español. Estás leyendo la versión en inglés.

Misión:Choose an isolation level on MySQL that prevents the loan check from seeing uncommitted data, without paying for more isolation than needed.Contexto · Objetivos de aprendizaje ▾

Pocketly's loan check reads the customer's balance while a large incoming transfer is still being verified. The transfer is later rolled back by fraud detection, but the loan was already approved. Years ago someone set the reporting connection pool to READ UNCOMMITTED “for speed”, and the loan service reused it.

Misión: Choose an isolation level on MySQL that prevents the loan check from seeing uncommitted data, without paying for more isolation than needed.

Objetivos de aprendizaje

  • Define a dirty read.
  • Map isolation levels to the anomalies they prevent.
  • Know that engines differ (PostgreSQL never reads uncommitted data).
SimulaciónSimulado

Ejecuta la simulación para ver la salida.

Ejecutar simulación
-- loan-check service (MySQL / InnoDB)SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;   -- "faster dashboards", added years agoSELECT balance FROM account WHERE id = 7;                    -- may read another transaction's uncommitted write-- fix: READ COMMITTED (each statement sees only committed data)SET SESSION TRANSACTION ISOLATION LEVEL READ COMMITTED;

Simplificación

Relative costs are illustrative. In practice READ COMMITTED and REPEATABLE READ cost about the same in MVCC engines; SERIALIZABLE adds retries. Modelo educativo: los números ilustran un comportamiento, no son benchmarks.

Conceptos

Retos relacionados

Referencias