The Microservice architecture implementation with cloud patterns is explained in this article. Usually, the request will send from the Client-side to the gateway and the gateway will pass the request to a particular service interface (Repository Pattern). Then the interface will pass the request to the CQRS pattern, which will return the data from the database. Before accessing the database it will check the data is available in Cache or not. If data is available in Cache, the client request will return from the cache.
The below mentioned are the cloud patterns from Azure:
- Repository Pattern
- CQRS Pattern
- Cache Pattern
What is the Repository Pattern?
The repository pattern is intended to create an abstraction layer between the data access layer and the business logic layer of an application. It is a data access pattern that prompts a more loosely coupled approach to data access. The data access logic is created in a separate class, or set of classes called a repository with the responsibility of persisting the application’s business model.
Using the Repository Pattern has many advantages:
- The business logic can be unit tested without data access logic.
- The database access code can be reused, centrally managed, and easily implemented
- Access policies, like caching
- The domain entities or business entities are strongly typed with annotations; and more.
What is CQRS design pattern?
Command Query Responsibility Segregation (CQRS) is another architectural design pattern used in microservices architecture which will have a separate service, model, and database for insert operations in the database. This acts as a command layer that performs an action or a query that returns data
Command: It is a method that either change the state of an object, has side-effects, or fulfills both criteria at the same time. However, a command deliberately does not return a return value, which is why it cannot return any information about the state of an object.
Query: It is a method that returns information about the state of an object, but must not influence this state or have any other side effects.
What is Cache Aside Pattern?
The Cache Aside pattern improves the performance by utilizing caches while reading data from the data store. This pattern can be used to read and update operations of data to and from the data store. The different types of caches are
- In-Memory Cache is used when implementing cache in a single process. When the process dies, the cache dies with it. If the same process needs to run on several servers, a separate cache needs to be used for each server.
- Persistent in-process Cache is used when there is a requirement of cache backup outside of process memory. The backup can be in form of a file, or in a database. However, in case of process restart, the cache will be lost.
- Distributed Cache is used when there is a requirement for shared cache for several machines such as servers. With a distributed cache, it is stored in an external service. This means if one server saved a cache item, other servers can use it as well.