0

We don't know where to implement a certain enum and how to propagate it throught our services, that need it. We need this enum "SampleType" in two of our microservices (for now). Our services communicate mostly via REST endpoints with autogenerated client files via Swagger. We have one repository service for our "inventory data", that is shared across most of our services, that reads from and writes to our main databases. Some of our other services have their own small dbs for certain things that are specific to these services.

So, this SampleType enum is specific to one service A, but is needed in at least one to two other services B and C as well. A is writing objects with this enum into its own db. It communicates with at least B and C via REST and sends and receives these objects that contain the enum.

For safety reasons, A would need to define at least its own SampleType because it writes it to a db. But it would be nice if we could define it in our main repository service and propagate it without future issues to all services that need it via REST endpoints (swagger includes enum definitions). There is logic behind this enum, so a centralised change would need to flag issues at compile time.

We have also tried using a central library which is distributed to the services as a Nuget package, however this results in two separate definitions (nuget + swagger).

What are generally preferrable ways of defining and propagating the enum definition? Is there a simpler way or is it indeed mandatory in such cases that a service defines its own enum and maps if necessary?

5
  • An Enum is used to work against at compile time. How should propagating from somewhere help? That a runtime thing. What you have is part of an interface definition and if you fear that the definition on certain services are different then get your versioning of the REST API in between correct. Enum change -> version change. Commented May 6, 2024 at 9:30
  • 2
    If SampleType is specific to service A it should probably be part of Service As public API. But you write nothing about your version handling strategy. If Service A is modified, Service B should be able to continue using the older API for some time, and an enum change would be considered an API change. Commented May 6, 2024 at 9:31
  • @JonasH Of course you are correct. If A is modified, B should be able to still function. However, and this I did not mention yet, these services are running live production. So in case of an update, we generally know what the dependencies are and update everything at the same time, resulting in a few seconds of downtime, which is completely fine. However...we'd like a way around those dependencies somehow. We're just not sure if there is a way around or just "best practice." Another way of asking the same question: where to define the enum and propagating its definition in what way? Commented May 7, 2024 at 7:11
  • "update everything at the same time" - then why are you using micro services? Independent deployment is one of the key reason for picking the pattern. Are you sure you do not have a distributed monolith? Commented May 7, 2024 at 7:36
  • Not every architecture can be clearly defined as monolithic or independent. The backend services function independently but they are in constant communication with each other. This is live production in a factory environment. Maintainability for us generally is fast and well managable while downtime is absolutely minimal. However, this is not part of the question at all. Commented May 7, 2024 at 12:44

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.