The Real Fullstack

The Dirty Read

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

エンジニア7 分タイムラインシミュレーターコード課題
sqlpostgresqlmysqlsql-server

この課題はまだ日本語に翻訳されていません。英語版を表示しています。

ミッション:Choose an isolation level on MySQL that prevents the loan check from seeing uncommitted data, without paying for more isolation than needed.背景 · 学習目標 ▾

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.

ミッション: Choose an isolation level on MySQL that prevents the loan check from seeing uncommitted data, without paying for more isolation than needed.

学習目標

  • Define a dirty read.
  • Map isolation levels to the anomalies they prevent.
  • Know that engines differ (PostgreSQL never reads uncommitted data).
シミュレーションシミュレーション値

シミュレーションを実行すると出力が表示されます。

シミュレーションを実行
-- 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;

簡略化

Relative costs are illustrative. In practice READ COMMITTED and REPEATABLE READ cost about the same in MVCC engines; SERIALIZABLE adds retries. 教育用モデルです。数値は挙動を示すためのもので、ベンチマークではありません。

コンセプト

関連する課題

参考資料