The debate over whether to use a schema or not has passionate support on both sides. One side appreciates data integrity constraints and predictability, while the other prefers more flexibility (or “agility”) and time effectiveness. The ultimate answer as to which is “better” most likely depends on the specific project, data used, and associated skill set.
In this post I will cover strict schema enforcement, schemaless, and dynamic schema, including the pros and cons of each one.
A schema is a blueprint of how a database is constructed. It doesn’t actually hold the data, but instead describes the shape of the data and how it might relate to other tables in the database. Schema’s contain information on all the objects in a database such as tables, attributes, data types and relationships, it can also include triggers, views, indexes and so on. Some common databases that use strict schemas are Oracle, MS SQL Server and PostgreSQL.
Pros:
Cons:
As the name implies, schemaless does not use a schema. It means the database does not have any fixed structure. A schemaless database does not enforce any data type limitations and can store structured and unstructured data. Some common schemaless databases are MongoDB, CouchDB, and Google Cloud Datastore.
Pros:
Cons:
What many claim as the best of both worlds, a dynamic schema is one that changes as you add data. There is no need to define the schema beforehand. When data is inserted, updated, or removed, the database builds a schema dynamically. Popular dynamic schema databases include HarperDB and MongoDB.
Pros:
Cons:
As you can see, there are valid points on each side of the argument and numerous factors to considering when choosing which is right for your specific project. At the end of the day, this decision has a lot to do with the preference of the user and long term project goals. For example, at HarperDB, we are big fans of the dynamic schema, which enables us to ingest any type of data at scale. HarperDB frees you from the hassle of defining data types, providing unlimited flexibility as your applications evolve and scale over time. Which type of schema do you prefer?
While it may not be top of mind, it’s important to get your schema right upfront to avoid unnecessary headaches and additional time and costs later on. Foundation is key, and it’s much more difficult to go back and change that foundation once you’ve actually built on top of it. Take the time to weigh the pros and cons of strict schema enforcement vs. schemaless vs. dynamic schema before you start building, you won’t regret it.