1

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)

arminvanbuuren
  • 957
  • 1
  • 9
  • 16
  • This is all up to the architect. If a DB, will all hosts have access? Or will there be another micoservice responsible for DB interactions? Cache / Shared memory? How are other hosts (you said salable cluster) going to access this information across the network, without knowing where it is? – Matt Clark Jul 31 '18 at 23:15
  • 1
    yes, this is a question about architect, you're right. Are there any best practice how to build such architect? Use zookeeper to orchestrate for example – arminvanbuuren Jul 31 '18 at 23:53

2 Answers2

2

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.

Saptarshi Basu
  • 8,640
  • 4
  • 39
  • 58
1

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

Fabio Manzano
  • 2,847
  • 1
  • 11
  • 23