Over a million developers have joined DZone.

MongoDB & Bitcoin: How NoSQL Design Flaws Brought Down Two Exchanges

DZone's Guide to

MongoDB & Bitcoin: How NoSQL Design Flaws Brought Down Two Exchanges

· Java Zone
Free Resource

Microservices! They are everywhere, or at least, the term is. When should you use a microservice architecture? What factors should be considered when making that decision? Do the benefits outweigh the costs? Why is everyone so excited about them, anyway?  Brought to you in partnership with IBM.

On March 3rd, the Bitcoin exchange Flexcoin shut down after being hacked and catastrophically robbed. The hack was made possible, according to Emin Gün Sirer in this recent post on the topic, by a concurrency problem brought on by the use of NoSQL databases. To illustrate the problem, Sirer offers an analogy based on ATM withdrawals:

Now, consider what would happen if I duplicated my debit card, gave it to my best friend, synchronized our watches, and performed withdrawals at two different ATMs at the same time.

What's that I hear you say? Absolutely nothing bizarre would happen. My account would be deducted the right amount. That's because banks employ systems that guard against this kind of elementary error. They are based on transactions with ACID guarantees.

But if our bank was implemented using a first-generation NoSQL datastore, say MongoDB, we'd see something very different.

Hacked websites and flawed code are not necessarily notable events, but this one stands out, not only because of the quantity of the loss (896 BTC, according to Sirer), but because of the simplicity of the problem: These kinds of concurrency issues are well-known and there are numerous ways to get around them. From Sirer's point of view, the big problem is not this individual failure, but that these issues are built into NoSQL solutions:

Yes, yes, the broken-by-design apologists will trot out the usual refrain that goes "there is nothing wrong with MongoDB as long as you always deploy it knowing that it can give you back bogus answers." Yeah well, there is nothing wrong with flammable mattresses either, just make sure there is no source of ignition nearby. It just turns out that we then get charred family tragedies, because people are fallible.

And as it turns out, it wasn't just a fluke issue with Flexcoin. Sirer points to another Bitcoin exchange, Poloniex, which suffered from the same design flaw, and he even points to a possible third example as well. The scary part, Sirer suggests, is the built-in nature of the problem. This wasn't a burglars-picking-your-lock situation, after all; it's more like the door was left open. 

Check out Sirer's full post for more details on the collapse of Flexcoin and Poloniex, and for thoughts on how one might avoid such catastrophes even when using NoSQL databases.

Discover how the Watson team is further developing SDKs in Java, Node.js, Python, iOS, and Android to access these services and make programming easy. Brought to you in partnership with IBM.


Opinions expressed by DZone contributors are their own.

The best of DZone straight to your inbox.

Please provide a valid email address.

Thanks for subscribing!

Awesome! Check your inbox to verify your email so you can start receiving the latest in tech news and resources.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}