Service discovery

Server-side discovery

click to edit

digram

examples

Client-side discovery

diagram

client-side-discovery

examples

Netflix OSS

Eureka

Ribbon

benefits

Fewer moving parts and network hops compared to Server-side Discovery

drawbacks

This pattern couples the client to the Service Registry

Need to implement client-side service discovery logic for each programming language/framework used by your application, e.g Java/Scala

server-side-discovery

AWS Elastic Load Balancer (ELB)

Kubernetes

benefits

Compared to client-side discovery, the client code is simpler since it does not have to deal with discovery. Instead, a client simply makes a request to the router

Some cloud environments provide this functionality, e.g. AWS Elastic Load Balancer

drawbacks

Unless it’s part of the cloud environment, the router must is another system component that must be installed and configured. It will also need to be replicated for availability and capacity.

The router must support the necessary communication protocols (e.g HTTP, gRPC, Thrift, etc) unless it is TCP-based router

More network hops are required than when using Client Side Discovery

Self Registration

examples

Netflix Eureka

benefits

A service instance knows its own state so can implement a state model that’s more complex than UP/DOWN, e.g. STARTING, AVAILABLE, …

drawbacks

Couples the service to the Service Registry

must implement service registration logic in each programming language/framework that you use to write your services, e.g. NodeJS

A service instance that is running yet unable to handle requests will often lack the self-awareness to unregister itself from the service registry

Reliability

Circuit Breaker

examples

Netflix Hystrix

Observability

Log aggregation

examples

drawbacks

handling a large volume of logs requires substantial infrastructure

Distributed tracing

Data management

examples

Exception tracking

benefits

It is easier to view exceptions and track their resolution

drawbacks

The exception tracking service is additional infrastructure

examples

Health Check API

examples

Spring Boot Actuator

benefits

The health check endpoint enables the health of a service instance to be periodically tested

drawbacks

The health check might not sufficiently comprehensive or the service instance might fail between health checks and so requests might still be routed to a failed service instance

Log deployments and changes

examples

references

benefits

Enables deployments and changes to be easily correlated with issues leading to faster resolution.

Application metrics

examples

Instrumentation libraries

Metrics aggregation services

AWS Cloud Watch

benefits

It provides deep insight into application behavior

drawbacks

Metrics code is intertwined with business logic making it more complicated

issues

Aggregating metrics can require significant infrastructure

Audit logging

examples

This pattern is widely used.

benefits

Provides a record of user actions

drawbacks

The auditing code is intertwined with the business logic, which makes the business logic more complicated

Related patterns

Event Sourcing is a reliable way to implement auditing

Security

Access Token

Database per Service

Shared database

Event sourcing

External API

API gateway

Backend for front-end

Testing

Consumer-driven contract test

Consumer-side contract test

Service component sest

Communication

Transactional messaging

Polling publisher

Transactional outbox

Transaction log tailing

Style

Remote Procedure Invocation

Messaging

Domain-specific protocol

Deployment patterns

Multiple service instances per host

Service instance per host

Service instance per VM

Service instance per Container

Serverless deployment

Service deployment platform

Cross cutting concerns

Microservice chassis

Externalized configuration

UI patterns

examples

benefits

The identity of the requestor is securely passed around the system

Services can verify that the requestor is authorized to perform an operation

Related patterns

The API Gateway uses this pattern.

32O08gT5

12Aa8MJgL7effSC^

purpose

keep each microservice's persistent data private to the service

different ways

Private-tables-per-service – each service owns a set of tables that must only be accessed by that service

Schema-per-service – each service has a database schema that’s private to that service

benefits

Helps ensure that the services are loosely coupled. Changes to one service’s database does not impact any other services.

Each service can use the type of database that is best suited to its needs.

a service that does text searches could use ElasticSearch

a service that manipulates a social graph could use Neo4j.

drawbacks

Implementing business transactions that span multiple services is not straightforward

Implementing queries that join data that is now in multiple databases is challenging.

Complexity of managing multiple SQL and NoSQL databases

solution

API Composition

solution

Saga pattern

Command Query Responsibility Segregation (CQRS)

click to edit