What are microservices?
For decades, the traditional monolithic software architecture was the dominant choice for building applications. In recent years, however, monolithic architectures have been disrupted by lightweight, efficient microservices. But what are microservices exactly, and how do microservices work?
What is a microservice?
The microservices architecture refers to a software model in which a single application is actually composed of multiple smaller, loosely coupled services. Each of the services in a microservices architecture has a highly specific function, like the assembly line in a manufacturing plant.
Microservices are often contrasted with the "monolithic" software architecture, in which all of these various services are combined in a single application. The benefits of monolithic applications may include simpler development and testing and higher performance, thanks to sharing the same resources. However, monolithic applications come with a major disadvantage: the tight coupling between different components means that the application may be too inflexible and have scalability issues.
By contrast, microservices are loosely coupled by design, giving developers much greater flexibility, agility, and scalability. Each individual microservice can easily be scaled up or down, without affecting the other application components.
The term "microservices" is often used in conjunction with the concept of service-oriented architecture (SOA). Like microservices, SOA applications break up the components of monolithic applications into multiple service modules. However, microservices are usually considered an evolution of the SOA concept: microservices are typically smaller than the services of an SOA application, and also capable of functioning independently.
Major technology companies such as Netflix, Amazon, eBay, and Apple have all used microservices to great success. For example, Netflix migrated its previous monolithic software architecture to a service-oriented model. With the need to deal with more than 1 billion calls per day, Netflix's move to microservices greatly benefited the company's ability to scale up during times of high demand.
How do microservices work?
Microservices can either be built from scratch, or developers may decide to decompose an already-existing monolithic application. The decomposition process is often repetitive and multi-step, dividing a process over and over until reaching a set of fine-grained task that correspond to individual microservices.
For example, an e-commerce website may have the following high-level functions:
- Inventory management
- Catalog management
- Order management and fulfillment
- Product recommendations
- Customer service
Each of these functions may be further broken down into smaller functions. For example, the high-level goal of inventory management will require a microservice that updates the number of items in stock after a user places an order.
For developers' convenience, microservices often communicate using application programming interfaces (APIs). APIs are intermediary protocols that define how two different applications interact and exchange information.
Microservices are often linked with containers, another development concept that has risen in popularity in recent years. Containers are software "packages" that combine an application's source code together with its runtime environment: the dependencies, libraries, and settings that are necessary for the application to run.
By using containers, developers can guarantee that an application will behave predictably even when running on different machines. Containers work well with microservices-based applications because they allow you to deploy an individual microservice in separate locations, while running within a consistent environment.
Microservices with Redis
Microservices applications, like traditional monolithic software, need a database in order to store and retrieve information. But what database is best for microservices? Many microservices developers are choosing database solutions like Redis.
Redis is an open-source, in-memory data structure store that is used to implement NoSQL key-value databases, caches, and message brokers. As an in-memory database, Redis has a light footprint and has been explicitly designed not to handle excess amounts of data when not absolutely necessary. This philosophy of efficiency works well together with microservices, which have each been designed for a particular function—and nothing else.
Microservices applications may consist of hundreds or thousands of services, which means that microservices developers need a database that supports scalability and high availability. Redis fits that bill. Solutions such as Redis Cluster and Redis Sentinel are used to implement distributed databases using Redis, helping the underlying database be just as scalable and flexible as the microservices application it supports.
The good news is that you can also use a microservices architecture if you use a third-party Redis Java client such as Redisson, which implements many familiar Java objects, collections, and other constructs. Redisson includes support for Redis-based reliable Java microservices communication with remote procedure calls (RPC), messaging, and cache.