API Gateway

Prajakta KhatriPrajakta Khatri
3 min read
  • It is an API management tool that sits between a client and a collection of backend services.

  • It serves as a single entry point for all API requests, offering a unified interface to access different services and data.

  • By separating client applications from backend microservices, API Gateways simplify API management and improve the system's overall performance and security.

Features of API Gateway

  • Request Routing: Routes incoming API requests to the appropriate backend services or microservices, based on defined rules, paths, or headers.

  • Parameter Validation: Ensures that incoming requests adhere to the required formats.

  • Whitelist Verification: Ensures that only approved entities can access the service

  • Authentication & Authorization: Verifies client credentials before allowing access to resources.

  • Rate Limiting: Safeguards services from being overwhelmed by controlling the number of incoming requests.

  • Service Discovery: Locates the services responsible for handling specific requests.

  • Request Transformation: Adjusts request formats to align with the requirements of different microservices.

  • Error Handling: Provides clear and user-friendly responses while managing errors efficiently.

  • Caching: Stores frequently requested data to enhance response times.

  • Whitelist Verification: Ensures that only approved entities can access the service

  • Logging & Monitoring: Tracks and logs all activities for analysis and performance monitoring using tools like Elastic.

Benefits of API Gateway

Efficiency

  • Optimized Traffic Routing: Routes requests efficiently to the right service, improving performance.

  • Caching: Stores frequent responses to reduce backend load and speed up responses.

Security

  • Centralized Security: Ensures secure access with authentication, authorization, and encryption.

  • Rate Limiting: Protects against traffic overload and DDoS attacks.

Flexibility

  • Request Transformation: Adjusts request/response formats for compatibility.

  • Dynamic Routing: Routes requests based on service availability and traffic needs.

Scalability

  • Load Balancing: Distributes traffic to handle high demand.

  • Autoscaling: Works with cloud systems to scale services based on real-time needs.

API Gateway vs Load Balancer

  • An API Gateway acts as the gatekeeper for your microservices, managing and routing requests securely while controlling access to each service. It determines who can access what and directs requests to the appropriate service.

  • A Load Balancer ensures smooth operation by evenly distributing traffic across service instances, preventing any one instance from being overwhelmed.

  • Together, they form the backbone of scalable, resilient architectures.

  • Path a (Application Load Balancer - ALB):

    • Operates at OSI Layer 7, handling HTTP, HTTPS, and gRPC traffic.

    • Routes requests based on headers or URL, providing advanced content-based routing.

    • It does not support static IPs and is used for web-based applications with complex routing needs.

  • Path b (Network Load Balancer - NLB):

    • Operates at OSI Layer 4, managing traffic like TCP, UDP, and TLS without inspecting the contents.

    • Offers static IP support and is ideal for high-performance, low-latency traffic.

Both paths lead to the API Gateway, which manages additional tasks such as authentication, rate limiting, and routing to services.

Disadvantages of API Gateway

Performance bottleneck

If the API Gateway is the central point through which all traffic flows, its failure would disrupt the entire system. This means no requests would reach the backend services, resulting in downtime for the entire application unless redundancy is built in.

Increased latency

Since the API Gateway processes all incoming requests (such as handling authentication, rate limiting, and routing), it adds a layer of overhead. If not optimized, this additional processing could slow down request handling, negatively affecting system performance.

Scalability challenges

As traffic increases, if the API Gateway isn't scaled appropriately (vertically or horizontally), it could become overwhelmed, leading to delays or failures in processing requests. Proper load balancing and scaling strategies are essential to prevent this bottleneck.

Complexity

Configuring an API Gateway involves setting up routing, security, authentication, rate limiting, and other rules for each service. As the system grows, managing these configurations can become complex and error-prone, especially when handling multiple services, policies, and environments.

0
Subscribe to my newsletter

Read articles from Prajakta Khatri directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Prajakta Khatri
Prajakta Khatri

๐Ÿ‘ฉโ€๐Ÿ’ป Hello World, Iโ€™m Prajakta! ๐Ÿš€ Learner| Developer| Tech Enthusiast