2

My company, which specializes in logistics and transportation, delegated the majority of the backend microservices to our team. All of the microservices (which our team inherited from "past generations") appear to have inconsistent input field validation. Mobile number format validation is a good example. There would undoubtedly be a need to add other validations, such as prefixes and other mobile number lengths to take into account, if our clientele expanded to other nations.

Also, not all microservices read from the same databases.

How should this mobile number format validation be centralized across all microservices? The only other option that comes to mind is creating a separate microservice for this, but this seems to be an overkill considering that for now, this will only be applied to mobile number format validation. The same is true for Drools, a business rules engine. Are there other available options for smaller scale rules like this one?

3
  • 5
    How many services need to handle mobile numbers? I would have expected most validation to be done by the service responsible for user data. And are you sure the validation should be the same? A number for reporting critical system errors might have different requirements from one used for marketing for example.
    – JonasH
    Commented Aug 17, 2023 at 11:48
  • 1
    "The same is true for Drools, a business rules engine." What is the same exactly? You lost me here.
    – JimmyJames
    Commented Aug 17, 2023 at 15:17
  • 4
    Sharing code can be done in many ways, among others: (1) exposed as microservice to be used by other microservices; (2) making a DLL that is used in the build of microservices; or (3) directly including shared/common source code in the build of microservices.
    – Erik Eidt
    Commented Aug 17, 2023 at 15:17

1 Answer 1

9

If the microservices are written in the same language (or languages which can use libraries in a common language) it makes most sense to define a validation library and import it in the various projects.

Such a library would typically be relatively stable, with occasional additions for new kinds of data, and sometimes changes for edge cases. As such, a change to it would rarely force dependents to be recompiled and redeployed, which serves to decouple the different microservices. A library also incurs very little overhead at runtime and very moderate development overhead.

If there are complex, potentially changing business rules which need to be evaluated reliably by all affected services, implementing them as a separate "rules" microservice may make sense. However, for simple input field validation this would indeed be overkill.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.