ace
ace

Reputation: 12044

How distributed databases such as Redis and Cassandra work in Microservices architecture?

Suppose I have a microservice that updates or reads data from Redis and Cassandra. Now suppose I scale up and have 3 instances of exact same microservice. Do I need to 3 instances each for Redis and Cassandra so each instance of microservice has its own instance of Redis and Cassandra? Or since both Redis and Cassandra are cluster based distributed databases, I will not need 3 instances of these databases but share the same cluster among the 3 instances of the microservices?

What if MySQL is also being used by the microservice, will I need 3 instances of MySQL?

Upvotes: 2

Views: 431

Answers (1)

islamhamdi
islamhamdi

Reputation: 207

You can have a microservices architecture with a service scaled up to 3 instances, but uses a single instance of a database (redis/mysql/....), or you can have a cluster of the databases connected together (more than 1 instance of redis/mysql).

The idea is that you don't restrict a single replica/instance talking to a single replica/instance of the database, that's not the reason to scale up your architecture, i.e: you don't assign an instance of the database to an instance of the running service. It works this way

Service Load Balancer (routes traffic to a single instance) ---> cluster of instances --> DB Load Balancer --> routes traffic to a master node in the DB cluster (or whatever setup you use other than master-slave or master-master or consistent hashing).

TL;DR: Don't assign a database replica per service replica, later on you might need to scale your services to 10 replicas, but have a database cluster of only 3 nodes.

Upvotes: 1

Related Questions