Part 1 Mistakes of a Software Engineer - Favor NoSQL over SQL - Part 1
There is nothing called Schemaless
One argument that people usually make about NoSQL is the flexibility in schema designing. They are Schemaless databases and very similar to objects in programming language. The dynamic schema is very powerful and can support several different use cases, not limited like what SQL provides. You can simply throw your objects into it and do anything you want.
Is it really true? For me, it’s NOT.
There is nothing called Schemaless. The schema just moves from Database level to Application level. For Document databases, you are actually using implicit data schema model (compare to explicit data schema in SQL). Instead of letting the database handle the schema and datatype itself, you have to do it yourself in your application code.
- Some databases support simple schema validation. However, none of them are as optimal as what SQL provides. You are limited to just some basic data types (string, number, boolean,…) while SQL offers a wide range of different data types for different use cases (for example: varchar, nvarchar text,… just for string data). Working with strict data type is always easier and more performant.
- In case you handle the schema yourself, it may be ok if you use a static-typed programming language (like C#). However, if you are developing your application using Nodejs, Ruby, PHP,… (which is quite common for Startup companies), you have to maintain another layer of schema validation in your application because the data is just runtime objects.
Schema migration is also another problem. NoSQL databases encourage you to just throw the objects
into and not care much about the schema. Some databases don’t even require you to create any table, simply
write the data and the tables will be created automatically.
When you read/write the data, it is hard to know which version the data is on. You will
have to add many if
statements just to check for what should have been provided. No matter
how careful you design your application, how strict your coding conventions are, there will always be the
case your code works with outdated data schema. For critical business workflows, I want
everything to be expressed clearly, not implicitly.