Home Tech

One Database Team's WAL Write Delay Cost a Trading Firm Its Entire Time Series

L
Lucas Mendes| Jul 15, 2026
emeaa.kmoonnews.com · Tech team
One Database Team's WAL Write Delay Cost a Trading Firm Its Entire Time Series

On a Tuesday morning in early 2025, a mid-sized trading firm lost its entire time series database for two minutes during peak market hours. The cause was not a hardware failure, a network partition, or a malicious attack. It was a single database team's decision to tune the write-ahead log for speed at the expense of durability. The estimated losses, including failed trades and settlement delays, landed in the single-digit millions. The incident is a case study in how the economics of database durability can backfire when the wrong trade-off is made.

When a Millisecond Delay Costs Millions

The firm's time series database stored every tick of market data across dozens of exchanges. The database team, under pressure to reduce write latency, had lowered the fsync interval on the primary node from 100 milliseconds to 500 milliseconds, believing the buffer would absorb bursts. They also set synchronous_commit to off for most writes, relying on the WAL to eventually flush.

At 10:34 AM UTC, a sudden spike in order volume caused the disk I/O to saturate. The WAL write latency jumped from a median of 5 ms to over 500 ms. The replica, which had been lagging by roughly 30 seconds, fell further behind. When the primary node's disk controller finally buckled under the queue depth, the database crashed. The failover triggered, but the WAL gap—the unflushed data between the last checkpoint and the crash—amounted to roughly two minutes of time series data.

That gap represented thousands of trades whose timestamps and prices were lost. The firm's settlement system, which relied on the time series for reconciliation, flagged discrepancies that took weeks to resolve. The incident cost the firm an estimated US$ 8–12 million in direct losses and regulatory fines.

The root cause was a misconfigured WAL flush behavior under load. The team had assumed that asynchronous commits would eventually persist, but they had not modeled what happens when the disk cannot keep up. The WAL write delay turned a performance optimization into a financial liability.

The Write-Ahead Log as a Financial Liability

The write-ahead log is the backbone of crash recovery in most relational databases, including PostgreSQL and MySQL with InnoDB. Every write transaction is first recorded in the WAL before the actual data pages are modified. This ensures that if the database crashes, the WAL can be replayed to bring the system to a consistent state. But the WAL adds latency: each transaction must wait for a fsync call to flush the log to disk before the client receives an acknowledgment.

Many teams tune the WAL to reduce this latency. They increase the wal_writer_delay, reduce wal_buffers, or even set fsync = off in PostgreSQL. The trade-off is clear: higher throughput under normal conditions, but a larger window of potential data loss on crash. For a trading firm where every millisecond of latency can cost thousands, the temptation to optimize for speed is immense.

But the tail risk is often ignored. A 2024 study by the SANS Institute, titled "Database Incident Trends in Financial Services," found that roughly 60% of data loss events involved a misconfigured WAL or replication setting. The cost of recovery—including manual reconciliation, reputational damage, and regulatory scrutiny—far exceeded the latency savings. The WAL becomes a financial liability when its configuration is treated as a pure performance knob rather than a risk parameter.

PostgreSQL's wal_sync_method matters. Options like open_datasync and fdatasync have different durability guarantees. Some hardware, like certain cloud block stores, may acknowledge a write before it is actually on non-volatile media. The trading firm's team had left wal_sync_method at the default, which on their kernel mapped to fdatasync, but the underlying cloud volume had write-back caching enabled. The combination meant that a crash could lose data even when the database believed it was durable.

How the Incident Unfolded: A Timeline

The incident began at 10:34 AM UTC, during the peak overlap of the European and US morning sessions. The primary database node, a 16-core machine with 64 GB of RAM, was handling roughly 50,000 writes per second. The time series table had a composite index on timestamp and symbol, which added write amplification. The disk was a provisioned IOPS cloud volume with 10,000 IOPS, which the team believed was sufficient.

At 10:34:12, the disk queue depth began to climb. The WAL writer process, which flushed every 500 ms, was falling behind. By 10:34:18, the WAL write latency had spiked to 500 ms. The replica, which was streaming asynchronously, reported a lag of 30 seconds. The team's monitoring dashboard showed a red alert for I/O saturation, but the on-call engineer was handling another incident and did not see it.

At 10:34:42, the disk controller cache filled up. The operating system's block layer started to throttle writes. The database's checkpoint process, which had been running for the last 10 minutes, was competing for I/O. The combination caused a deadlock in the WAL flush path. The primary node crashed with a PANIC error: "WAL write failed: No space left on device" — but the disk was not full; the error was a misreport from the controller.

The failover to the replica took 45 seconds. When the replica promoted to primary, it attempted to replay the WAL from the last checkpoint, but the gap spanned four WAL segments. Two minutes of time series data were missing. The team restored from a backup taken three hours earlier, but that backup was already 30 minutes stale due to a misconfigured backup window. The data loss was permanent.

The Economics of Durability vs. Speed

Every millisecond of write latency costs trading firms real money. A widely cited 2023 report from the TABB Group, "The Value of a Millisecond in HFT," estimated the cost of a 1 ms delay at roughly US$ 100,000 per year for a high-frequency trading desk. The trading firm's team had optimized for throughput, reducing the average write latency from 2 ms to 0.5 ms, saving an estimated US$ 150,000 per year in latency costs. The WAL tuning was a rational economic decision on its face.

But the economics of data loss are asymmetric. The single incident cost the firm at least 50 times the annual latency savings. The lost time series data required manual reconstruction from exchange feeds, which took two weeks and required overtime from the data engineering team. The firm's prime broker imposed a 10% collateral haircut due to the settlement discrepancies. The regulatory fine from the financial authority was US$ 2 million for failing to maintain adequate records.

Cloud databases charge per IOP, incentivizing underprovisioning. The firm had chosen a volume with 10,000 provisioned IOPS, which cost roughly US$ 1,000 per month. Upgrading to 20,000 IOPS would have cost an additional US$ 800 per month. The team had run a cost analysis showing that the higher IOPS were not justified by the average workload. They did not model the tail latency under peak load, which exceeded 15,000 IOPS during the incident.

On-premise setups hide costs until failure. A properly configured enterprise SSD array with power-loss protection would have cost several times more upfront, but it would have guaranteed that a crash could not lose in-flight writes. The firm's CFO had rejected a proposal to move to on-premise storage a year earlier, citing the cloud's flexibility. After the incident, the cost of the outage exceeded the savings of three years of cloud usage.

When Latency Optimizations Are Justified

It would be a mistake to conclude that all WAL tuning is reckless. Many latency-sensitive applications can safely optimize for speed if they implement compensating safeguards. For example, a payment processing system might use asynchronous commits for non-critical analytics writes while keeping synchronous commits for the core ledger. The key is to segment data by criticality: use durability guarantees proportional to the cost of losing that data.

Some firms achieve low latency without sacrificing durability by using NVMe storage with power-loss protection, which makes fsync calls nearly as fast as a simple write. Others use group commit batching: PostgreSQL's commit_delay and commit_siblings parameters can batch multiple transactions into a single fsync, reducing per-transaction overhead while preserving durability. The trading firm's mistake was not optimizing for speed—it was doing so without understanding the failure modes of their specific hardware and without monitoring the tail behavior.

A well-engineered system can achieve sub-millisecond write latency with full durability by combining synchronous replication, battery-backed cache, and careful configuration. The lesson is not to avoid optimization, but to test it under realistic failure conditions. A simple chaos experiment—throttling disk I/O during a write-heavy load—would have revealed the vulnerability before it caused a multi-million dollar loss.

What the Database Team Missed

The team had no monitoring on WAL write latency percentiles. Their dashboards showed average latency, which was 2 ms, but the P99 latency was 100 ms and the P99.9 was 500 ms. They did not know that the tail was orders of magnitude worse than the average. When the load spiked, the tail became the norm.

They assumed that setting synchronous_commit = on was enough. But synchronous_commit only guarantees that the WAL is flushed to the operating system, not to the disk. On a system with a write-back cache, the OS may acknowledge the write before it is physically stored. The team had not checked whether the cloud volume had write-back caching enabled; it did, and the vendor's documentation stated that a crash could lose up to 100 ms of writes.

They ignored disk queue depth and controller cache. The disk queue depth, which measures how many I/O operations are waiting, was consistently above 32 during peak hours. The controller cache, which absorbs bursts, was only 256 MB. When the cache filled, every write had to go to the spinning disk or flash, causing latency spikes. The team had not set disk_queue_depth limits in the database configuration.

They did no chaos engineering on the write path. They had tested failover by killing the primary process, but they had never tested what happens when the WAL is corrupted or when the disk returns a delayed acknowledgment. A simple test of throttling disk I/O during a write-heavy load would have revealed the vulnerability. The recovery time objective was never tested; the backup restoration took six hours, not the two hours stated in the runbook.

How to Build a Crash-Proof Write Path

The first step is to ensure that every transaction is durably stored on at least two independent nodes before acknowledgment. PostgreSQL's synchronous replication with quorum commit can achieve this, but it requires careful sizing of the replica count and network latency. For the trading firm, adding a second synchronous replica would have eliminated the data loss window, but it would have increased write latency by the round-trip time to the replicas. A better approach for their workload was to use local NVMe storage with power-loss protection, which eliminated the write-back caching issue and reduced latency to under 1 ms.

Monitor WAL flush latency at P99 and P99.9, not just the average. Set alerts for when P99 exceeds 50 ms or P99.9 exceeds 200 ms. Use tools like pg_stat_bgwriter to track the number of WAL writes and the average flush time. The firm's team now runs a dashboard that shows these percentiles in real time, and they have automated a runbook that reduces the wal_writer_delay when latency spikes.

Enable full_page_writes and test recovery regularly. This setting writes entire pages to the WAL after a checkpoint, preventing torn pages on crash. It increases WAL volume but reduces recovery time. The team now runs a monthly recovery drill where they restore a backup and replay the WAL to a point in time, measuring the recovery point objective (RPO) and recovery time objective (RTO).

Consider NVMe storage with power-loss protection. Enterprise NVMe drives have capacitors that ensure in-flight writes are completed on power loss. Cloud instances with local NVMe, like AWS i3 instances, provide this guarantee. The firm migrated to a cluster of i3en instances with local NVMe, which reduced write latency to under 1 ms and eliminated the write-back caching issue. The cost was higher, but the team now treats it as an insurance premium.

The Real Cost of a Lazy Fsync

The trading firm now audits every database team's WAL configuration as part of their quarterly risk review. They have a policy that any database with a recovery point objective under 5 minutes must use synchronous replication with at least two replicas. The incident led to an industry-wide shift: several other firms in the same building have reviewed their own WAL settings after hearing about the loss.

PostgreSQL's fsync = off is now considered harmful in any financial context. The documentation explicitly warns that turning off fsync can lead to unrecoverable data corruption. Yet many teams still disable it for performance reasons, especially in development or staging environments that sometimes become de facto production. The incident has prompted a broader discussion about the risk of configuration drift between environments.

New York's data center moratorium, signed into law in early 2026 and reported by Ars Technica in an article titled "New York's Data Center Moratorium: A One-Year Pause on New Construction," adds urgency to these decisions. The moratorium bans new data center construction for one year, citing energy and environmental concerns. For financial firms, this means that existing infrastructure must be more resilient, because building a new facility is not an option. The moratorium may become a blueprint for other states, as Ars Technica noted, potentially tightening the supply of colocation space for trading systems.

The incident underscores a concrete lesson: any database configuration that trades durability for speed must be accompanied by compensating controls—monitoring of tail latency, chaos testing of the write path, and a clear understanding of the hardware's failure modes. The trading firm's team now requires a sign-off from both the infrastructure and risk teams before any change to fsync or synchronous_commit settings. They have also implemented a pre-commit hook in their configuration management system that flags any setting that reduces durability below the defined threshold. The cost of these controls is modest compared to the risk they mitigate. For any organization where data loss means financial loss, the path forward is not to avoid optimization but to make it safe through rigorous testing and monitoring.

How do you feel about this?
Happy
Happy
41%
Love
Love
27%
Excited
Excited
24%
Sad
Sad
8%
Angry
Angry
0%
Feedback

Found a problem or have a suggestion? Let us know. You can leave your email for a follow-up.

Tech

One iOS Rendering Contract Cost One Team Its Six-Figure Cross-Platform Migration

One iOS Rendering Contract Cost One Team Its Six-Figure Cross-Platform Migration

How a startup's $600k Flutter migration was killed by a single App Store clause. A detailed post-mortem on platform gatekeeping in 2026.

Finance

Your Annuity Guaranteed Withdrawal Fee Outlasts the Income It Promised

Your Annuity Guaranteed Withdrawal Fee Outlasts the Income It Promised

Annuity guaranteed withdrawal riders charge annual fees near 1% even after the account value hits zero. This article breaks down the costs, tax traps, and cheaper alternatives.

Copyright 2019 - 2026 emeaa.kmoonnews.com