Are NoSQL databases for me?

Billy Lo
3 min readNov 18, 2018

--

Episode 17: Unexpected things I learned from building Sidekick & SpendSimple

Are NoSQL databases for me?

TL;DR — The tradeoffs between good old RDBMS (like MySQL) and new schema-less databases (like Firestore) are not obvious until you try building something with them first hand. Don’t assume new is better.

Sidekick, SpendSimple.ai and TravelShoppingBuddy.com were all built using NoSQL databases: Parse, PouchDB and Firestore respectively.

NoSQL is attractive for high velocity apps like Snapchat and Facebook as they ran into limitations of a traditional RDBMS which scale vertically (by adding more CPUs and memory to servers within a data centre).

Top 3 reasons why NoSQL is handy:

  1. Super-fast inserts/writes: It doesn’t matter if you have 2 billions documents already in the same collection.
  2. Schema-less: Developers can add/change fields as they wish. No need to coordinate with DBAs or worry about column size or type.
  3. Eventual consistency: Perfect for allowing mobile apps to do stuff in disconnected mode and then sync with the master copy when it comes back online.

But do make sure you understand the tradeoffs before diving head-first with NoSQL. They are not very obvious (at least to me.)

  1. Most of them don’t support JOINs, GROUP BY, SUM/MIN/MAX, things that you have likely taken for granted in good old SQL-based engines. You can achieve them using MapReduce, but it takes a bit of learning to get used to and do them right.
  2. You need to maintain a specific index for each way you query your data! (e.g. sort by date, sort by amount, filter by name.)
  3. BI / reporting tools on top of NoSQL databases are not as well-developed. Expect to spend more time creating data aggregation for KPI reporting, slicing-and-dicing using different dimensions. The fact that it’s schema-less also adds to the difficulty.
  4. Bulk operations like “UPDATE table SET field = ‘abc’ WHERE filter = ‘xyz’” takes more effort to code.
  5. Transactions and atomicity of operations can be done, but requires careful thinking.
  6. JavaScript code for NoSQL data access is not portable. It took me a fair bit of work to move SpendSimple from Firestore to PouchDB.

Parse was best-in-class back in 2015 (very rich in functionality for any mobile apps) until Facebook bought it and then stop enhancing it :-( . It’s still available in open-source; and can get good hosting services at low cost.

PouchDB was chosen for SpendSimple for its unique ability to push data updates from server to client and client to server. Very cool.

Firestore is very handy if you use Firebase for everything else and just need simple data storage and basic CRUD operations.

MongoDB is the most mature and actively enhanced these days.

Here is the good news: NewSQL databases like Google Cloud Spanner, Microsoft CosmosDB, CockcoachDB and FoundationDB are bringing the best of both worlds.

IMHO, good old RDMBSes like MySQL is still a solid choice unless you know you will run out of room for vertical scalability on day one or latency (for global audience) is critical to you.

--

--

Responses (1)