6th Choosing Your Database
6th Choosing Your Database
By Komal Konkati
How to choose the right database for your service
Choosing which database to use is one of the most
important decisions you can make when working on a
new microservice.
• While there is a convergence happening in some general-
purpose databases (that support various models relational /
document / key-value at the same time) like MySQL and
PostgreSQL, which claim to make your life easier,
How you are going to fetch your data is one of the main ways
to find the best database for your use case. If you are going to
fetch data by key, then all you need is a key-value store (e.g.
DynamoDB, Redis, S3, GCS).
In case you mostly fetch via key, but sometimes you also need
to fetch by one or two other fields, then Wide-Column DBs
(e.g.DynamoDB, Cassandra) may be right for you.
On the other hand if you will require to query by many
different fields you can choose either Relational DB
(e.g.MySQL, PostgreSQL) or Document DB (e.g.MongoDB,
CouchDB, MySQL, PostgreSQ). Note that Document DBs
don’t support well queries that require joining data from
multiple documents.
Consistency
In case you need to read your data right after your write it (i.e.
strong consistency) than a Relational database (e.g. MySQL,
PostgreSQL) is usually more suited than a Document Database
(e.g.MongoDB, CouchDB), especially in case of multi-data-center
scenario.
• Storage Capacity
Most database systems are limited by the amount of
space on disk (e.g. MySQL) or struggle with performance
as amount of Nodes and Shards grows into the hundreds
(e.g. Elasticsearch).
In case you have very high traffic and require very low latency,
Cloud providers solutions like Amazon’s DynamoDB and
Google’s Bigtable could be just what you need. As long as your
service is deployed on the same data center as the database,
you can enjoy latencies that are under 10ms. The downside is
of-course the $ cost.
Maturity and Stability