Sunday 13 December 2020

NoSQL vs SQL For Beginners

Often times, we compare and contrast two popular DBMS paradigms, NoSQL and SQL. While we are all conversant with the basics of these two kinds of systems, significant developments in the recent versions of two technologies themselves has rendered a lot of our understanding moot.

5 years back, the following would have been the most common distinction between NoSQL and SQL as far as their applicable use cases concern-

NoSQL -

  1. You have a read/write heavy system with little to no updates.
  2. You want horizontal scaling flexibility
  3. You have a simple lookup use case with no/minimal joins between related collections/tables.
  4. You need the flexibility of a schema-less design and have arbitrary schema for each document in your collection.
  5. You believe that denormalized data storage eliminates need for joins at runtime.
SQL - 
  1. Your system is transactional in nature and as such needs to leverage ACID capabilities offered by a typical SQL solution
  2. You conceive little to no changes in data model/schema.
  3. You have planned your design for at least 3 years ahead into the future and any further performance improvements needed then shall be addressed simply with vertical scaling of your database servers.
  4. Oracle is the leading enterprise SQL solution and you don't need all the bells and whistles of a paid solution for a backend system that supports clients within your own enterprise.

Many of the above are simply true even today and need no further explanation. But here are a few that I believe would benefit from explicit reiteration - 

The premise that SQL databases cannot be horizontally scaled is simply not true. You can horizontally scale even your SQL databases by sharding your indexes if you think it will grow too huge for an index that can be completely held in memory. 

I guess about 15 years back, we were living in a time where SQL and NoSQL had a strict distinction over their respective capabilities but today the gap between them has bridged greatly. Many characteristics of SQL have been borrowed into NoSQL solutions (think of joins, various consistency models other than eventually consistent, transactional capabilities etc.) and vice-versa (think of schema-less design with json/clobs).

So next time you get asked this question in an interview, feel free to confidently clarify any misconceptions the interviewers may themselves have.

Appendix- 
ACID - Atomicity, Consistency, Isolation, Durability
BASE - Basically Available, Soft state, Eventually consistent

No comments:

Post a Comment