Fast Prototyping: From Monolith to Microservices
Designing a distributed microservice architecture from nothing is tricky; this article shows you how to start with the monolith then divide it into microservices.
Join the DZone community and get the full member experience.Join For Free
One of the drawbacks of the microservice concept is that it is difficult to design a distributed microservice architecture right at the start of a project, and mistakes made at this stage can be very expensive. For this reason, the most common advice is to start with the monolith and then divide it into target microservices.
This article presents just such an approach to system prototyping.
As an example, we will use a task management system for a hypothetical support team. The system will be designed first as one application (monolith), and then divided into separate microservices.
To build the application we will use Cricket Microservices Framework, which is one of the lightest frameworks of this type for Java. Cricket is designed and optimized for this approach from the very beginning. This is due to the fact that the application can be easily divided into smaller elements by transferring selected adapters to them.
There will be 3 articles in total:
Fast prototyping: from monolith to microservices (this one)
An example task management system should have the following features:
Access to the system functionality should be possible only for logged in users. That is why we will need a module enabling user management and an authentication system.
We will implement the basic functionality of the ticketing system, i.e. creating tasks with a name and description and changing the status of the task to "completed."
It is worth to make the knowledge base available to users - as articles available after logging into the system.
All functionalities listed above should be available via the REST API. Thanks to this, it will be possible to create dedicated applications facilitating the use of the system. It can be a web application available through a browser or a dedicated mobile application.
Our system should be available through a web browser, so we will add an element that is a simple web application.
Sending Notifications of New Tasks
Creating a new task should cause sending a notification to all users. We will use for this purpose the API made available by Slack.
Cricket MSF for Fast Prototyping
Main features and architectural elements of the Cricket platform:
Embeded HTTP server
Automatic Java to JSON serialization
User and access management
Embeded databases: key-value, H2
Thanks to these features, the prototype building process can be limited to the coding of the task module and web app, while the remaining functionalities will be implemented using ready-made Cricket modules. This will significantly reduce the time it takes to create a prototype, and that is what we are looking for.
Stages of Prototype Building
We will do the prototype development in 3 main steps:
Building a monolithic application
Implementation of the Gateway API pattern
Dividing the application into microservices
The overall architecture of the monolithic application is based on the hexagonal architecture of the Cricket platform. The assumed functionalities are implemented by dedicated adapters.
The target system will consist of a set of separate microservices, each of which will be responsible for a specific functionality. Since the aim of the article is to show the procedure of prototyping and decomposition of the monolith, and not the very design of microservices, let's arbitrarily accept this set as correct.
The process of building a monolithic application will be described in the article "Fast Prototyping: Building of the Monolith."
Published at DZone with permission of Grzegorz Skorupa. See the original article here.
Opinions expressed by DZone contributors are their own.