Basics of Microservice Architecture
By: Ajay Yadav
Tags: Software Architecture, Software Engineering, Software Development, Microservices, Microservice Architecture

Monolith

The system as a single deployable or executable unit.

Hexagonal architecture

An architecture in which the core of the application is business logic and surrounded by the adapters.

Adapters are of two types:

INBOUND ADAPTER

Handle incoming requests by invoking the business logic.

E.g. REST API adapter, Web UI adapter

OUTBOUND ADAPTER

External systems are invoked by business logic via outbound adapters.

E.g. Database, External APIs like Twilio.

Benefits of monolithic architecture (When the application is small)

Simple to develop: No complexity of the distributed system

Easy to test: Easy to write E2E automation test cases.

Easy to deploy: Single deployable file e.g. WAR

Easy to scale: Can run multiple instances with the load balancers

Drawbacks of monolith

Development is slow: Loading a large codebase, building, understanding, and running is slower.

Deployment is slower: Many developers committing to the same codebase can result in it into an unreliable state and running tests on a complete codebase is slower.

Scaling is difficult: Different modules/team has different resource requirements e.g. some modules are CPU intensive and others may be memory intensive.

Less reliable: Lack of fault isolation, all modules run under a single process, and error in one module results in incomplete application failure.

Obsolete tech stack: It’s really arduous to change the complete tech stack of the monolith at one time and hence team usually adapts to old tech stacks.

CI/CD

Continuous Integration (CI)

Continuous Integration (CI) is a development practice where developers integrate code into a shared repository frequently, preferably several times a day. Each integration can then be verified by an automated build and automated tests.

Continuous Delivery

Deploy changes to the production many times a day.

Continuous Deployment V/S Continuous Delivery

MICRO-SERVICE ARCHITECTURE CONTEXT

An architecture has very little or no effect on the functional requirements (use cases) of a service.

Architecture directly has an impact on the non-functional requirements (quality of service) of the services. It includes maintainability, extensibility, and testability.

Scale Cube

As per the book (Art of scalability), there is a three-axis of scalability described as follow:

X-Axis: Running multiple instances behind the load balancer

Z-Axis: Running multiple instances each with a shard of data.

Y-Axis: Functional decomposition of the services.

Y-Axis which represents the functional decomposition of the services is the basics of microservice architecture.

Microservice architecture (MSA)

An architectural style that functionally decomposes a complex application into a set of services.

Each service is modular.

Each service is loosely couple and communicates with each other over APIs. Each service has its own database.

Benefits of Microservice Architecture

Enable continuous deployment and delivery of large and complex applications: Automation testing is easier for small applications. Each service is independently deployable.

Services are small and easily maintainable: Code is easy to understand and IDEs are able to load, compile, and run faster.

Independently scalable

Better fault isolation

Each service can independently adapt to the new tech stack.

Drawbacks of the microservice architecture

Identifying the right services is difficult.

Each service has its own database which makes transactions and queries as complex.

PATTERNS IN MICROSERVICE

Pattern

A pattern is a reusable solution to a problem in a particular context.

Structure of pattern

Forces

Resulting Context

>> Benefits

>> Drawbacks

>> Issues: New problems that are introduced as a result of using this pattern.

Microservice Architecture Patterns

MSA patterns are divided into three categories

Infrastrucutural patterns

Application patterns

Infra + Application patterns

INFRASTRUCTURAL PATTERNS

Deployment

Discovery

External APIs

APPLICATION PATTERNS

Decomposition

Querying

DB architecture

Data consistency

Testing

INFRA + APPLICATION PATTERN

Security

Cross-cutting concerns

Reliability

Communication style

Transaction messaging

observability

IPC: Inter-process communication patterns

There are 5 groups of communication pattern

Communication style

Discovery

Reliability

Transactional messaging

External APIs

Querying patterns

Saga

Composite API

CQRS pattern

Deployment patterns

Single service per host

Multiple services per hosts

Observability pattern

Health check APIs

Log aggregation

Distributed tracing

Exception tracking

Application metrics

Audit logs

Testing patterns

Consumer-driven contract test

Consumer side contract test

server component test

Security Pattern