arminvanbuuren
arminvanbuuren

Reputation: 1307

what are the best approaches (practices) to create stateful microservices?

I need to create a food ordering service, using microservices, scalable , cluster, several steps to order. Need to store user data between steps / requests.

What is an approach to keep state and user data? Store it in DB? Cache? Shared memory? Are there any tutorials for the best practice of it?

(I gonna use spring / springboot and modules)

Upvotes: 1

Views: 596

Answers (2)

Fabio Manzano
Fabio Manzano

Reputation: 2865

If you are looking for a fully managed service, AWS provides "Step Functions" to satisfy your stateful requirements: https://stackoverflow.com/questions/tagged/aws-step-functions

Upvotes: 1

Saptarshi Basu
Saptarshi Basu

Reputation: 9303

Anything that you cannot afford to lose (usually the business data) will go in DB and can be parallelly cached in an in-memory DB like Redis that has a cache eviction algorithm inbuilt.

Anything that, if lost, is not a big deal (usually the technical things that are not directly linked with the business data) can go only in an in-memory DB.

Since you are using Spring, you could probably use something like Redis with Spring Data Redis. There are already known Spring solutions (such as this) to fall back on api calls to fetch data from DB if the Redis server goes down. You can also run multiple Redis instances behind Redis Sentinel to provide failover. Redis Cluster provides a way to run a Redis installation where data is automatically sharded across multiple Redis nodes. Also, you can configure Redis to persist the data in file system once daily or so to backup the cache data for disaster recovery.

Upvotes: 2

Related Questions