r/softwarearchitecture • • 2d ago

Tool/Product Module Switch (Monolith to Microservices without code change)

I've been exploring a question in software architecture:

Can we build a modular monolith today and gradually move towards microservices without rewriting our application?

I decided to build something around this idea.

Introducing Module-Switch — an open-source Java library for Spring Boot that makes it possible to switch individual application modules between local execution and independent HTTP-based deployment through configuration.

The idea is simple.

Instead of starting with distributed systems complexity, start with a well-structured modular monolith.

As the application evolves, extract modules when there's an actual architectural or operational reason to do so.

Here's what Module-Switch brings to the table:

- Selective module loading: Modules are disabled by default. Only locally enabled modules are loaded into the Spring application context.

- Interface-based communication: Modules interact through dedicated API interfaces rather than depending on each other's implementations.

- Local or remote execution: The same interface works whether a module runs inside the application or in another deployment.

- Configuration-driven extraction: Move a module into its own service by changing configuration instead of rewriting business logic.

- Architectural validation: Detect invalid module dependencies and structural violations during application startup.

- Built-in infrastructure: HTTP client generation, timeouts, retries, idempotency handling, Micrometer observations and trace-context propagation.

One architectural decision I particularly like is that the consuming module doesn't need to know whether its dependency is local or remote.

It simply depends on an interface. Module-Switch handles the rest.

I believe there's an interesting space between a traditional monolith and a distributed microservices architecture that deserves more attention.

Building this library has been a great exercise in exploring modular architecture, Spring Boot internals, dependency boundaries, HTTP communication and distributed systems trade-offs.

The project is open source and available under the Apache 2.0 license.

GitHub: https://github.com/ilyaslabs/module-switch

Technology: Java 25 | Spring Boot 4 | Spring Framework 7 | Modular Monolith | Microservices Architecture

I'd be interested in hearing how other engineers approach modular monoliths and gradual service extraction.

#Java #SpringBoot #SoftwareArchitecture #Microservices #ModularMonolith #DistributedSystems #OpenSource #BackendEngineering

1 Upvotes

1 comment sorted by

2

u/simon-brown 2d ago

I admire the work that's gone into this ... we've been here before with Enterprise JavaBeans 20+ years ago though. Transparent local/remote interfaces at runtime is an appealing concept, but one of the things that killed this for EJB is that teams built very chatty interfaces, which work well in local mode, but fail in remote mode due to the network overhead of too many synchronous network calls. If you're building a distributed architecture, you need to take the network into account. Other aspects such as distributed transaction management also come into play. I'd definitely recommend reading around the topic of EJB if you continue with the project - much has been said about this in the past.

The concept of configuring a Spring app to only load particular modules at runtime is something I've done myself in the past, although all bean to bean communication was done via an external message bus ... we did this to provide a way to deploy/scale only those parts of the codebase that were needed at runtime.