TLDR: Mo2oM is a novel framework that transforms monolithic software into microservices using a ‘soft clustering’ approach, allowing code components to belong to multiple services. Unlike traditional ‘hard clustering’ methods, Mo2oM leverages deep semantic embeddings from large language models and structural dependencies to create more cohesive, less coupled, and better-balanced microservice architectures. Evaluations show significant improvements in modularity, reduced inter-service communication, and more even service distribution compared to existing techniques, offering a flexible solution for both new migrations and refactoring existing microservices.
Modern software development is increasingly moving away from large, single-unit applications, known as monoliths, towards a more modular approach called microservices. Microservices break down an application into smaller, independent services, each handling a specific business function. This shift aims to improve how easily software can be scaled, maintained, and deployed.
However, many existing methods for breaking down monoliths into microservices face a significant challenge: they use ‘hard clustering.’ This means each part of the software, like a class, is assigned to only one microservice. While seemingly straightforward, this rigid approach often leads to problems. For instance, if a software component serves multiple functions, forcing it into a single microservice can increase the need for different services to communicate with each other (inter-service coupling) and reduce the internal consistency within a single service (intra-service cohesion).
Interestingly, real-world observations of how experts decompose software show a different picture. Practitioners often intentionally duplicate or share certain software components across multiple services. This ‘overlapping’ membership helps reduce communication overhead, as a shared component doesn’t need to be called across service boundaries. This insight led researchers to question whether allowing components to belong to more than one microservice could actually improve the overall quality of microservices-based systems.
Furthermore, traditional methods for understanding code semantics (its meaning and intent) often fall short. They might use simple text analysis techniques that miss the deeper functional relationships embedded in the source code. The rise of large language models (LLMs) for code understanding presents a new opportunity to capture these rich semantic connections, leading to more functionally coherent microservice decompositions.
Introducing Mo2oM: Overlapping Microservices for Better Software
To address these limitations, a new framework called Mo2oM (Monolithic to Overlapping Microservices) has been proposed. Mo2oM is the first framework to treat microservice extraction as a ‘soft clustering’ problem. Instead of a binary assignment, Mo2oM assigns each class a membership score, indicating its probability of belonging to various microservices. This allows components to probabilistically belong to multiple services, mimicking expert-driven decompositions.
Mo2oM combines two crucial types of information: deep semantic embeddings and structural dependencies. Semantic embeddings are generated by a large language model (specifically, UniXcoder, fine-tuned for source code) that captures the functional and semantic similarities between code elements. Structural dependencies are extracted from method-call graphs, showing how different parts of the code interact architecturally. By combining both, Mo2oM gets a comprehensive view of class relationships.
The framework then uses a graph neural network (GNN)-based soft clustering algorithm to generate the final set of microservices. This process results in a membership matrix, where each class is assigned to all services where its membership value exceeds a certain threshold. This flexible approach allows for shared class ownership, reducing the need for costly inter-service calls.
Also Read:
- AI-Powered Tools for Navigating Complex Codebases
- Enhancing Code Completion with Adaptive Context Filtering
Demonstrated Improvements and Flexibility
Mo2oM was rigorously evaluated on four open-source monolithic Java applications: JPetStore, DayTrader, AcmeAir, and Plants. It was compared against eight state-of-the-art baseline methods. The results were compelling: Mo2oM showed significant improvements across key metrics. It achieved up to 40.97% improvement in structural modularity (balancing internal consistency and external dependencies), 58% reduction in inter-service call percentage (communication overhead), 26.16% reduction in interface number (simpler system with fewer dependencies), and 38.96% improvement in non-extreme distribution (more balanced service sizes).
An important aspect of Mo2oM is its flexibility. It allows users to specify the target number of microservices upfront, making it adaptable to different organizational budgets and resource constraints. This is a significant advantage over methods that determine the service count internally. Furthermore, Mo2oM isn’t just for migrating monoliths; it can also be used to refactor existing microservices that might be poorly designed, demonstrating its practical applicability in improving even ‘ground-truth’ microservice architectures.
In conclusion, Mo2oM offers a novel and effective solution for microservice extraction by embracing soft clustering and leveraging advanced deep semantic embeddings. This approach leads to more modular, efficient, and balanced microservice architectures, suitable for both initial migrations and the ongoing refactoring of modern software systems. To learn more about the technical details, you can read the full research paper here: Extracting Overlapping Microservices from Monolithic Code via Deep Semantic Embeddings and Graph Neural Network-Based Soft Clustering.


