0

Problem

We have multiple microservices, like Home, Menu & Cart, exposed via Gateway. Each one has API exposed to the app. Now, each API has certain information that is needed by the successive API. Wanted to know the best way to persist this information.

Possible Solution 1

One solution that comes to mind is to give the client(App in this case) the responsibility to share this information, given in the response of the current API, to the following API call. The app interacts via contracts and hence these are always bound via contracts.

Downside

Backward compatibility of the client is hard to achieve as it will need to add new params to the contract & new release is needed every time.

Possible Solution 2

Creating a session microservice, which holds contextual information of each API. Each API will ping this service for information. Since it will be an S2S call, contracts will be honored. App involvement will also be removed.

Downside

Creating a service looks like an overkill

Possible Solution 3

Each service maintains information about its own sessions. Every successive API fetches information of the previous sessions via S2S calls & works accordingly.

Downside

Doesn't look like good practise.

4
  • 1
    Is the system you're describing very large, as in Amazon or Facebook large? Because if it isn't, this seems like over-architecting. How do you persist state? You store it in a database. How do you retrieve it? You make an API call. How do you architect it? It could be as simple as a single gateway. Commented Nov 30, 2022 at 13:01
  • Well, you have decided to make a mash-up. Not a single source of trust for the app. That's arguably a good approach if you can not deal easily with breaking changes. Note that all 3 options will suffer backward compatibility when APIs change their contract, doesn't matter if you deploy a new version of the service or publish a new version of the app. You have to do one of the two if not both. Coupling won't go magically, you have to choose where you want it. Commented Nov 30, 2022 at 13:16
  • What are the API calls and what information is shared between them? Commented Nov 30, 2022 at 14:00
  • Sounds to me like you're working with a distributed monolith rather than a collection of microservices. Commented Sep 4, 2023 at 1:10

1 Answer 1

-1

Since software architecture is very contextual, it's hard to answer confidently without more details.

However, one possible solution to this problem could be using a shared cache or database that all microservices can access. Each microservice can store and retrieve the necessary information without relying on the client or creating a separate session microservice. This approach would also avoid the downsides of the other solutions you mentioned, such as the need for backward compatibility with the client or the potential overkill of creating a new session service.

This is a simpler version of solution 2.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.