Skip to content

Latest commit

 

History

History
56 lines (47 loc) · 3.29 KB

File metadata and controls

56 lines (47 loc) · 3.29 KB

API Composition

Motivation

  • Problem of retrieving data from multiple services in a microservice architecture.

Solution

Concepts

  • Uses an API composer to retrieve data from multiple services and combine the results.
  • An API composer can be a client or a service.
    • A service can a API gateway or a standalone service.

Implementation

  • Decide who plays the role of the API composer
    Decision Situation
    Not a client
    • Clients that are outside of the firewall and access services via a slower network.
    A standalone service
    • The data combination logic is complex.
    • The query operation is also used internally by other services.
    API gateway
    • The data combination logic is simple.
    • The query operation is for external calls.

Pros & Cons

Pros

  • Simple and useful.

Cons

  • Increased overhead (larger network latency and buring more system resources).
  • Risk of reduced availability (One service may be unavailable during the query operation).
  • A query operation may return inconsistent data.

Consideration

Topic Consideration Possible Solution Options
Scalability The data needs to be combined can be large.
Complexity The data combination logic can be complex.
  • Consider to put the API composer as a standalone service (The logic is too complex to be part of an API gateway).
Availability One service may be unavailable during a query operation.
  • Consider to let the API composer return previously cached data from the unavailable service.
  • Consider to let the API composer return incomplete data.
Performance The latency can be increased by calling multiple services.
  • Consider to let the API composer call multiple services in parallel if there is no dependency between the service calls (Sometime it may be impossible, an API composer needs the result of one service in order to invoke another service).
  • Consider to use asynchronous I/O to ensure that delay at the backend services doesn't cause performance issues in the client.

When To Use

  • A client needs to communicate with multiple backend services to perform an operation.
  • The client may use networks with significant latency

References