In the world of software development, there are bugs that lead you on a real-life detective investigation. Today, I'll tell you about one such story from my time at AWS.
Alert! Data Corruption
Imagine: a typical workday, the hum of servers, the quiet tapping of keyboards... and then, the alarm bells. Well, not real alarms, but the ones that go off in monitoring dashboards and support chats. One of our key services was raising a red flag: Data Corruption.
The system was reporting checksum mismatches when processing data received from another service. In simpler terms, we were receiving a file, and our verification was saying, "What's inside doesn't match what's on the label."
The first thought? A temporary glitch. "Just try again," says the internal voice of every engineer. We tried. The error repeated. And again. And again. It became clear: this wasn't a random occurrence. This wasn't a problem you'd expect in a typical application. This was something more fundamental.
In Search of the "Flipped Bit"
We had to roll up our sleeves and dive into the raw data. After several hours of analysis, we found the culprit: a single bit flip. For some reason, a single bit in a massive stream of data had been inverted. A zero had become a one. That was enough to throw our entire data integrity verification system into a frenzy.
We manually corrected that bit, recalculated the checksum - and it all matched! The processing continued, the fire was extinguished. But the main question remained unanswered: where did it come from?
The most interesting part began - the investigation. We needed to trace the path of this data through the entire AWS infrastructure. And that, I tell you, is quite a task when you have hundreds of microservices and tens of thousands of servers. We followed the trail from service to service, checking logs and metrics, until the trail led us to a specific piece of "hardware."
The culprit turned out to be... a network card. One of thousands. It was quietly going haywire and occasionally corrupting the data passing through it. A hardware problem, hidden deep within the data center. We replaced the card, and the problem disappeared forever.
Why Didn't Anyone Notice It Sooner?
But wait, if the data passed through several services, why did only we raise the alarm? The answer turned out to be surprisingly simple: not everyone was checking checksums. In our case, the "corrupted" checksum was "nested" - it only verified the integrity of a small fragment within a larger data packet. The previous services were too lazy to look that deep.
This incident forced us to rethink our approach to reliability. We implemented what you might call "checksum bracketing." The idea is simple, but effective:
1. Received data (D) with a checksum (C)? Immediately verify:
checksum(D) == C. Make sure the data arrived intact.2. Need to transform the data? Perform the transformation, get new data (
D'), and calculate a new checksum for it (C').3. Determinism check: To ensure that our transformation logic and the hardware itself are stable, we can perform the transformation twice and compare the results.
D' and C' from the first attempt should be identical to D'' and C'' from the second. No bit flips during calculations!4. Final check before sending: We re-check the original data (
checksum(D) == C) to be sure that nothing has been corrupted in memory during all our manipulations.5. Send it on: Only after all these checks do the transformed data (
D') and its new checksum (C') go to the next service.The Moral of the Story
This story left us with three important lessons:
* Never trust data. Even if it comes from a neighboring service, your own service. Verify everything.
* At a large scale, everything breaks. When you have thousands of servers, the probability of a hardware failure is not an "if," but a "when." Your system must be prepared for it.
* Checksums are your best friend. This is a simple but incredibly powerful tool for ensuring data integrity and reliability.
And how do you protect your data from these kinds of "ghosts in the machine"?
#en #bugs #bugs
