Storing state

Depending on your service, you can store state using:

  • A relational database management system (RDBMS), such as MySQL or PostgreSQL
  • A non-relational database management system, or NoSQL, such as MongoDB or RethinkDB
  • An in-memory database (IMDB), such as Redis or Memcached

The first option is still the most commonly used one. You'll rely on stable and more than proven database systems that run in multiple systems and that you can find on any cloud service where you might want to deploy your microservice. Apart from the maturity of most solutions, a relational database, if properly set up, should give you consistency.

The second option is more recent compared to the first one. Usually, there are no fixed tables as in RDBMS, and you normally work with collections of documents that are just common JSON structures. It's more agile as there are usually no restrictions, and each document might have a different structure. The more agile, the less consistent.

All three options, depending on the specific system you choose, support replication, which should enable fault tolerance and improve speed in geographically spaced instances.

Let's try each of the three options using one of the suggested systems. Let's begin with the relational database, and use MySQL.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset