How to select a database for your next project!
Databases are like a tool-set. Choose the wrong one that will cost time and money both from your project.
It is important to choose the right one for the right project. Depends on project requirements and data type, the database always should be chosen first.
This article can be the ultimate roadmap for your next quest for DB.
Key-Value
Key-value databases are simple and easy to understand. As the name, this database contains keys and values like javascript object or python dictionary. Every key should be unique and points to some values.
Example:
- Redis. (https://redis.io/)
- Mem-Cached. (https://memcached.org/)
- ETCD. (https://etcd.io/)
In the case of Redis and Mem-cached all the data held in memory, ths=is make the DB extremely fast but the amount of data will be limited.
Best For:
A key-value store is best in fast and small usage cases, especially your app's runtime data.
- Caching
- Pub/Sub
- LeaderBoards
- Message queues
Most of the time key-value DB use as a layer top on other DB.
Wide Column
It is like key-value DB with an extra dimension, like, each key point to one or more column families with a set of ordered rows. This makes it possible to holds related data together but unlike relational DB there is no schema that means it can hold unstructured data.
Example:
- H-Base. (https://hbase.apache.org/)
- Cassandra. (https://cassandra.apache.org/)
- Azure Table. (https://azure.microsoft.com/en-us/services/storage/tables/)
Best for:
Wide column DB de-centralize and can scale horizontally.
- Time-series data.
- Historical records
- High-write, low-read data.
Document DB
In this DB, there are documents, each document contains key-value pairs. They are unstructured and don't require a schema. Documents are group together in collections. Collections can be indexed and organized in a logical hierarchy.
Example
- MongoDB. (https://www.mongodb.com/)
- FireStore. (https://firebase.google.com/docs/firestore)
- CouchDB. (https://couchdb.apache.org/)
Document databases are a general-purpose database. Documents database read operation is faster than update or write. This is easy to use and developer-friendly.
Best for:
- Most mobile apps
- Games
- IoT
- Content management.
Don't use it for a graph or highly connected data.
Relational DB
They are here from the dawn of the database. Old but stable. Its structures as a table, which consists of rows and columns. Table connect with each other via foreign-key(FK)
. The main problem with this DB is the schema. This means if DB not architect properly it can be a mess on the latter path.
Example:
- MySQL (https://www.mysql.com/)
- PostgreSQL (https://www.postgresql.org/)
- MariaDB (https://mariadb.org/)
Usually, databases are ACID(atomicity, consistency, isolation, durability) compliance
Best for
Almost all applications. 90% of all applications available today are using one or another type of relational databases.
Don't use it for unstructured data and be cautious about the architecture step.
Graph
In this type of database, data represented a node and connection between them as the edge. It has the upper-hand when it comes to many-to-many relations in data. And much more and flexible modern in query approach.
Example:
- AllegroGraph (https://allegrograph.com/)
- Neo4j (https://neo4j.com/)
Graph databases are the best alternative for SQL when there is lots of join and relation within data.
Best for:
- Graphs.
- Knowledge graph.
- Recommendation system.
Search
In this category, databases should be able to fo a Fulltext search in a very short amount of time. Most of the DB in this category based on the:
Apache-Lucene Project (https://lucene.apache.org/)
Example:
- Solr (https://lucene.apache.org/solr/)
- ElasticSearch (https://www.elastic.co/)
- Algolia (https://www.algolia.com/)
From the developer perspective, they work very similarly to a document-oriented database. It starts with an index and data related to that index.
In the back, the database analyzes all the data and create a searchable index to deliver fast result.
Best for:
- Search Engine
- Type Head
Multi-Model
Most exciting out of them all. Think as a front-end developer, you need only the data you want which is not possible in most of the database and query system. They will return you with lots of another, which you need to map in the later and manipulate into a correct shape. Ultimately all of this operation will create performance issues.
The best tool for this is the query language called GraphQL(https://graphql.org/)
In these DB models, you can query only the things you need for your application.
Example:
- FaunaDB (https://fauna.com/)
Best for almost everything. The important bit is the query language itself, not the DB.
Which database you will select for your next project!