2

I'm working with microservices, and I see an issue.

There are two services, that transfer info between each other via jsons. Because of this, we have to store our enums in strings, and serialise-deserialise them while passing. The problem is - both services have to have copies of enums, to be able to translate those strings, and if one doesn't - there is a failure. We wrapped it up, so we don't get 500s, but the info, we could not deserialise, is just not displayed. I'm not sure though, maybe there is a better approach to it, where we don't have to keep in mind, where we have to update our enums, if the one is changed, and still have everything fully functional.

I'm really struggling with this. Microservices are to be isolated, and to be able to change freely, without affecting each other

1 Answer 1

9

Yes and No, You should have a client and model library published as part of the API project.

Consumers of the api can use this library. So they will be deserialising to the same dtos or entities that you serialised

If no library is available in the required language then the consumer will need to make one, and will hence need to make classes to deserialise the objects to, including enums.

The enum definition should be available as part of the documentation of the api. ie "possible values of field X are..."

There is an argument that clients should always make their own objects. But I think this is discredited these days. Obviously if your server side models are OOP style classes with methods that require dependencies then those methods are unlikely to be functional on the client. So it doesnt make sense for the client to use them.

With rest services though you are likely to be passing an anemic dto style object with no methods, so you might as well save the client some work and publish a model and client lib. The argument that this somehow increases the coupling between them is false. The coupling is due to the contract between the server and client, not the implementation of it.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.