Microservices Introduction
Microservice is a small, loosely coupled distributed service. Microservice architecture evolved as a solution to the scalability, independently deployable, and innovation challenges with Monolithic architecture (Monolithic applications are typically huge – more than 100,000 lines of code). It allows you to take a large application and decompose or break it into easily manageable small components with narrowly defined responsibilities. It is considered the building block of modern applications. Microservices can be written in a variety of programming languages, and frameworks, and each service acts as a mini-application on its own. Microservice can be considered as the subset of SOA(Service Oriented Architecture).
Reasons for using Microservice:
In monolithic applications, there are a few challenges:
- For a large application, it is difficult to understand the complexity and make code changes fast and correctly, sometimes it becomes hard to manage the code.
- Applications need extensive manual testing to ensure the impact of changes.
- An application typically shares a common relational database to support the whole application.
- For small changes, the whole application needs to be built and deployed.
- The heavy application slows down start-up time.
Benefits of Microservices:
- Small Modules – Application is broken into smaller modules that are easy for developers to code and maintain.
- Easier Process Adaption – By using microservices, new Technology & Process Adaption becomes easier. You can try new technologies with the newer microservices that we use.
- Independent scaling – Each microservice can scale independently via X-axis scaling (cloning with more CPU or memory) and Z-axis scaling (sharding), Y-axis scaling (functional decomposition) based on their needs.
- Removes dependency – Microservice eliminates long-term commitment to any single technology stack.
- Unaffected – Large applications remain largely unaffected by the failure of a single module.
- DURS – Each service can be independently DURS (deployed, updated, replaced, and scaled).
- Increased Security: –Microservices enable data separation. Each service has its own database, making it harder for hackers to compromise your application.
- Open Standards: –APIs enable developers to build their microservices using the programming language and technology they prefer.
Restrictions of Microservices:
- Configuration Management – As it becomes granular the headache comes with configuring the services and monitoring those. You need to maintain configurations for hundreds of components across environments.
- Debugging – Tracking down the service failure is a painstaking job. You might need to look into multiple services across different components. Centralized Logging and Dashboards are essential to make it easy to debug problems.
- Automation – Because there are a number of smaller components instead of a monolith, you need to automate everything – Builds, Deployment, Monitoring, etc.
- Testing – Needs a greater effort for end-to-end testing as it needs all the dependent services to be up and running.
- Coordination – While handling requests across multiple independent services there is a requirement for proper workflow management.
Microservice Frameworks for Java: There are several microservices frameworks that you can use for developing for Java. Some of these are:
- Spring Boot – This is probably the best Java microservices framework that works on top of languages for Inversion of Control, Aspect-Oriented Programming, and others.
- Dropwizard – Dropwizard pulls together stable, mature libraries from the Java ecosystem into a simple, lightweight package that lets you focus on getting things done.
- Restlet – Restlet Framework helps Java developers build better web APIs that follow the REST architecture style.
- Spark – A micro-framework for creating web applications in Kotlin and Java 8 with minimal effort.
Others that you can consider include Ninja Web Framework, Play Framework, RestExpress and Restx Framework.