0
0
Microservicessystem_design~12 mins

Ambassador pattern in Microservices - Architecture Diagram

Choose your learning style9 modes available
System Overview - Ambassador pattern

The Ambassador pattern is used in microservices to add a helper component (the ambassador) alongside a service. This helper manages communication tasks like logging, monitoring, or security, so the main service can focus on its core work. It helps keep services simple and reusable while handling cross-cutting concerns.

Architecture Diagram
User
  |
  v
+-----------------+
| Load Balancer   |
+-----------------+
        |
        v
+-----------------+       +-------------------+
| Ambassador      |<----->| External Service  |
| (Sidecar Proxy) |       +-------------------+
+-----------------+
        |
        v
+-----------------+
| Main Service    |
+-----------------+
        |
        v
+-----------------+
| Database        |
+-----------------+
Components
User
client
Initiates requests to the system
Load Balancer
load_balancer
Distributes incoming requests evenly to ambassador instances
Ambassador (Sidecar Proxy)
service_proxy
Handles communication tasks like retries, logging, and security for the main service
Main Service
service
Processes core business logic
External Service
external_service
Third-party or external system the ambassador communicates with
Database
database
Stores persistent data for the main service
Request Flow - 8 Hops
UserLoad Balancer
Load BalancerAmbassador (Sidecar Proxy)
Ambassador (Sidecar Proxy)External Service
Ambassador (Sidecar Proxy)Main Service
Main ServiceDatabase
Main ServiceAmbassador (Sidecar Proxy)
Ambassador (Sidecar Proxy)Load Balancer
Load BalancerUser
Failure Scenario
Component Fails:Ambassador (Sidecar Proxy)
Impact:Communication tasks like retries, logging, and security fail, causing possible request failures or security issues. Main service may receive unfiltered or unauthorized requests.
Mitigation:Deploy multiple ambassador instances with health checks and automatic restarts. Use circuit breakers and fallback mechanisms in main service to handle ambassador failures gracefully.
Architecture Quiz - 3 Questions
Test your understanding
What is the main purpose of the Ambassador in this pattern?
ATo store persistent data for the service
BTo handle communication tasks like retries and security for the main service
CTo balance load between users
DTo replace the main service logic
Design Principle
The Ambassador pattern separates communication concerns from the main service by using a sidecar proxy. This keeps the service focused on business logic while the ambassador handles retries, logging, and security. It improves modularity, reusability, and simplifies service code.