1

I am trying to learn microservices and write a project based on microservices, but I don't know how to choose the right database for each microservice?

Based on my researches MySQL and PostgreSQL are mostly used on big projects like Facebook, Instagram, Robinhood, etc. and also Cassandra and Redis are some of No-SQL databases used by Netflix and Instagram. I couldn't find any big project that uses MongoDB but it's very popular in educational contents and I don't know if is it a good choice for big projects as well?

In general, I want to know how to decide in which services or parts of the project we must( Or it's better to) use SQL and for what services it's better to choose NO-SQL databases? Are there any specific rules/instructions for this?

I see many projects like Instagram or Netflix use both SQL and No-SQL databases but I don't know how do they determine for which part they should use what kind of them?

EDIT: I also like to add up two more questions to make it more clear:

  1. Will we get into trouble if we only use either SQL or NO-SQL databases in a big application? When and why?
  2. Can we consider GraphQL as a solution for NO-SQL databases to meet data integrity or ACID rules? I mean what is the role of GraphQL in No-SQL world and could it make NO-SQL databases a complete replacement for SQL databases?
GoodMan
  • 111
  • 3

1 Answers1

1

I want to know at least the most important/major reasons/rules to decide which one is better to use...

In short:

Use a NoSQL solution when:

  • The schema is loosely defined and changes more frequently than you want to manage in the data layer
  • The schema is outside your control and is liable to change, such as when consuming an external API
  • Because you have no personal preference and don't care about data integrity

Use a SQL solution / RDBMS when:

  • Data integrity is important
  • You want to avoid a design that results in data duplication
  • Your schema is well defined or changes at a rate that's tolerable for you to manage in the data layer
  • Your data is relational

Either way, it's never a difference of query speed / performance despite what any article out there may misleadingly claim.

Some additional resources:

  1. NoSQL DB candidate for the project (looking for experienced advice)

  2. Should I use SQL vs NoSQL for files catalog?

...will update with more info and resources later.

J.D.
  • 40,776
  • 12
  • 62
  • 141