Development
4 min readMoving from monolithic architectures to microservices has universally changed how applications are built and maintained. In a monolithic system, everything runs together in a single environment, usually relying on one shared database. This makes data management easy but limits flexibility and scalability.
Microservices architecture enhances scalability and modularity by decomposing applications into smaller, independent services concentrating on specific business capabilities. Each microservice also leverages its own independent data source. This allows for faster development cycles and independent deployments. However, it increases deployment complexity.
To make microservices deployments easier to manage, Broadleaf provides a unique concept called Flex Packages. This offers a structured approach to deploying multiple microservices within a single application runtime (JVM), thereby significantly reducing complexity. However, it introduces a critical challenge: how do you maintain the independence of these microservices, especially at the data level, while allowing them to coexist within a shared deployment?
A monolithic system naturally maintains consistency because all services interact with a single shared database. In a "microlith" deployment like Broadleaf's Flex Packages, the runtime is shared between microservices, but the data sources remain distinct. As requests flow through the system, we must ensure strict data isolation so that each service's logic specifically targets its own independent data source and maintains its autonomy.
Without a proper data routing system, microservices operating within a shared deployment could inadvertently access or modify the wrong database, leading to inconsistencies, redundant data storage, and inefficient workflows.
This is where data routing comes in. By intelligently directing database operations to the correct data source based on the request’s context, services can operate independently while maintaining strict data separation within a shared environment.
A commonly recommended deployment approach in Broadleaf is the Balanced Flex Package.
In this model, services like Catalog, Menu, and Pricing operate within the same deployment unit. Despite sharing the same runtime, the services manage separate data. For example:
Both services follow the same structured translation framework but store separate translation data—they do not share records.
Additionally, the Tenant Service manages specific system-wide configurations, such as allowed locales, tenant-specific settings, and URL structures, and synchronizes them across services like Catalog and Menu. This ensures that global application configurations remain consistent while preventing unnecessary duplication at the service level.
Without a robust data routing system, this setup would lead to:
By automating database routing, Broadleaf ensures that each microservice interacts only with its designated database while allowing controlled synchronization of shared application configurations.
A routing data source acts as a mediator between services and databases, adaptively selecting the appropriate data source for real-time interaction.
The Process:
This approach allows multiple microservices to run within a single JVM while maintaining independent data access, eliminating the need for manual database configuration or unnecessary duplication.
Key Components of Broadleaf’s Data Routing Solution
Data routing is vital in microservices architecture, ensuring that each service connects to the correct database when needed while reducing overall deployment complexity. Without it, data management can quickly become a headache, leading to inefficiencies, inconsistencies, and unnecessary complexity. Broadleaf’s approach simplifies using a routing data source, thread-local contexts, and intelligent routing mechanisms. Organizations can adopt microservices quickly and gradually without the chaos of managing a fully distributed data system from day one.
Broadleaf’s data routing solutions help businesses manage microservices efficiently while maintaining data integrity. Explore our technical documentation or contact our team to learn more about implementation.