Skip to content

Latest commit

 

History

History
85 lines (75 loc) · 5.16 KB

API_Gateway.md

File metadata and controls

85 lines (75 loc) · 5.16 KB

API Gateway

Motivation

  • The client must keep track of multiple services.
  • Each service must handle some cross-cutting tasks, like authentication, authorization, etc.

Solution

Concepts

  • The single entry point into the backend services from external clients.
  • Offloads cross-cutting functionalities from individual services to the API gateway.

Functions

  • Core functions
    • Request Routing: Routes requests to one or more backend services, using layer 7 routing.
      • It can be based on method (GET, POST, etc.), IP, port, header, or URL.
    • API Composition/Aggregation: Aggregates multiple individual requests into a single request.
  • Cross-cutting functions
    • Monitoring, logging, analytics and billing
      • Metrics collection: Collects metrics on API usage
      • Logging: Log requests.
    • Security
      • Authentication: Verifies the identity of the client making the request.
      • Authorization: Verifies that the client is authorized to perform that particular operation.
      • SSL termination: Decrypts the SSL-encrypted requests from clients and pass on unencrypted requests to the internal services.
      • Certificate management
      • IP whitelisting and IP blacklisting
    • Protocol translation and service discovery
      • Protocol translation: Translates external requests in one protocol to internal requests in another protocol.
    • Rate limiting and circuit breaking
      • Rate limiting: Limits how many requests per second from either a specific client and/or from all clients.
      • Circuit breaking: The mechanisms to detect failures and recover quickly from failures
    • Caching
      • Caches responses to reduce the number of requests made to the internal services.

Solution Options

Implementation

  • Business logic should never be offloaded from the backend services to the API gateway.
  • Generates and injects correlation IDs into the requests for logging purposes and distributed tracing.

Pros & Cons

Pros

  • Encapsulates internal structure of the application.
  • Centralize the cross-cutting functionalities (authentication, authorization, etc.) into one place.
  • Reduces the number of requests/roundtrips by API Composition/Aggregation.

Cons

  • May introduce single point of failure.
  • May introduce performance bottleneck.
  • Must update the API gateway in order to expose a new services’s API.

Consideration

Topic Consideration Possible Solution Options
Reliability The API gateway may introduce single point of failure.
  • Consider to run multiple instances of API gateway.
  • Performance The API gateway may introduce performance bottleneck.
  • Make sure the API gateway is sufficiently scalable.
  • When To Use

    References