Search code examples
springdatabasespring-bootspring-mvcmicroservices

Configurable error messages in microservice architecture


We are using microservice architecture using spring-boot. For now, we are creating the messages in our code based on certain conditions.

We want to make the messages configurable by placing them in a database so that they can be changed and managed from a central position.

We have around 8-9 microservices and we have decided to add a new microservice (named commons-utils) in which we will create a database to place all the messages.

So, if a change is required in the message, we can just update the database. We can add different types of success and error messages, as well as the API custom response messages in the DB as they will be common to all microservices.

e.g.

ID | Code   | Messge                                        
1    ORD0001  Order placed by Client: {ClientName} 
2    ORD0002  Order Completed.
.
3    INV0001  Invoice generated for ordernumber: {Ordernumber}
.
11   NOT0001  Order accepted by Supplier: {SupplierName}
..

2..  A0001    Order was cancelled.

We will get all these messages after a successful login and store it in a cache probably, so that this commons-utils microservice is not called for getting every message and then get the message based on the code and populate it with the required values and then send it.

That's the implementation in our mind. I wanted to know if there are any better ways to do it.

Thanks in advance.


Solution

  • If the number of error messages can get quite large, the approach you are trying seems to be the best (Standing by the requirement that you need a central service). The hibernate cacheing mechanisms can give you good performance even though you are making db calls to fetch message.

    If your no. of messages can be controlled/maintained within a file, please make use of a configuration server as it can be up and running without much coding. Please refer: https://cloud.spring.io/spring-cloud-config/ This will allow you to make use of different profiles (corresponding to dev, qa, uat prod enviroments etc) easily and the properites can be managed using git. This would help you get started with a config server: https://spring.io/guides/gs/centralized-configuration/

    But in both scenarios, please keep in mind that if this service goes down, all your message scenarios would break!.