A single failing microservice should never take down your entire application. But without an API gateway and the right communication patterns, it will. The gateway is the control plane: routing, authentication, rate limiting, and circuit breaking all live there, keeping service failures contained and observable.
This guide covers the full API gateway and microservice architecture stack: gateway selection (Kong, AWS API Gateway, Traefik), service discovery, circuit breaker patterns, saga orchestration, event-driven communication with Kafka and RabbitMQ, service mesh with Istio and Linkerd, and Kubernetes deployment. By the end, you will have a clear architecture decision framework for building systems that degrade gracefully rather than failing catastrophically.
Monolithic vs. Microservice Architecture
The architectural decision between monolith and microservices is a tradeoff, not a clear winner. Understanding what you gain and lose from each helps avoid the common mistake of over-engineering early or under-engineering at scale.
A monolith puts all application logic in a single deployable unit. This is the right starting point for most products: lower operational overhead, simpler debugging, easier transactions across domain boundaries. The problems appear at scale — a bug in the payment module can take down the customer profile module, deploying a single change requires deploying the entire application, and scaling requires scaling everything rather than the one bottleneck service.
Microservices decompose the application into independent services, each with its own deployment lifecycle and data store. A change to the notification service can ship without touching the order service. The payment module can scale independently during peak checkout periods. The cost is distributed systems complexity: service discovery, network timeouts, distributed transactions, and observability all require explicit infrastructure.
Architecture Comparison
| Characteristic | Monolith | Microservices |
|---|---|---|
| Deployment | Single unit | Independent services |
| Scalability | Scale everything | Scale individual services |
| Technology stack | Single choice | Mixed stack possible |
| Data management | Central database | Distributed per service |
| Failure isolation | Full system affected | Single service affected |
| Operational overhead | Low | High |
| Team size sweet spot | Up to ~15 engineers | 15+ engineers |
The practical signal: when your team spends more time coordinating deployments than writing features, microservices have a strong case.
API Gateway Architecture
An API gateway is the single entry point for all client traffic — web, mobile, and third-party. It handles cross-cutting concerns that would otherwise be duplicated across every microservice: authentication, rate limiting, request routing, SSL termination, and observability.
Think of the API gateway as a receptionist at a large organization. It checks credentials, directs requests to the right department, and manages flow control. The individual departments (services) do their work without needing to worry about access control or traffic management.
Core Gateway Functions
- Request routing — directs incoming requests to the correct backend service based on path, headers, or query parameters
- Authentication — verifies JWT tokens or API keys before requests reach backend services
- Rate limiting — prevents any single client from overwhelming the system
- Response aggregation — combines data from multiple services into a single response (reduces client round trips)
- Protocol translation — converts between REST, gRPC, and WebSocket at the edge
- Load balancing — distributes traffic across multiple service instances
- Caching — stores frequent responses to reduce backend load
- Observability — logs every request with timing and status for debugging and analytics
API Gateway Comparison: Kong vs AWS API Gateway vs Traefik
Each gateway has a distinct operational model and fits different infrastructure contexts.
| Feature | Kong | AWS API Gateway | Traefik |
|---|---|---|---|
| Setup complexity | Medium | Low (AWS manages it) | Low |
| Scalability | High | Very high (auto-scales) | High |
| Cost model | Low/medium (open source) | Per-request billing | Free |
| Integration | Kubernetes, Docker | AWS ecosystem | Kubernetes-native |
| Plugin ecosystem | Extensive (600+) | Limited | Moderate |
| Performance | Excellent (Nginx-based) | Excellent | Good |
| GraphQL support | Yes | Yes | No |
| gRPC support | Yes | Yes | Yes |
| Vendor lock-in | None | AWS-specific | None |
Kong
Kong is an open-source enterprise-grade API gateway built on Nginx. Its plugin ecosystem covers authentication, rate limiting, caching, logging, request transformation, and more — all without writing custom middleware code.
Kong fits organizations that need full infrastructure control. You run it, you own the configuration, and you can customize behavior with custom plugins in Lua or Go. The tradeoff is a database requirement (PostgreSQL or Cassandra) and a steeper configuration learning curve than fully managed alternatives.
# Kong declarative configuration (deck)
services:
- name: customer-service
url: http://customer-service:3000
routes:
- name: customer-routes
paths: [/api/customers]
strip_path: false
plugins:
- name: jwt
config:
key_claim_name: sub
- name: rate-limiting
config:
minute: 100
hour: 2000
policy: redis
In production microservice deployments at Smart Maple — including a fintech platform serving multiple client applications — Kong runs with three replicas behind a load balancer, with custom authentication plugins that validate service-specific token claims before requests reach backend services.
AWS API Gateway
AWS API Gateway is the right choice when you are already running on AWS and want to minimize operational overhead. It handles scaling automatically, integrates natively with Lambda, IAM, Cognito, and CloudFront, and requires no server management.
The primary constraint is AWS lock-in. Moving away from AWS API Gateway means rewriting your routing and plugin configuration. For teams committed to the AWS ecosystem, this is a non-issue. For teams that want infrastructure portability, it is a meaningful constraint.
The billing model — per request plus per-GB data transfer — can become expensive at high request volumes. At 100 million requests per month, AWS API Gateway costs become significant compared to a self-managed Kong instance on EC2.
Traefik
Traefik is purpose-built for Kubernetes. It reads Kubernetes ingress annotations and service labels to configure routing dynamically — no manual configuration when new services are deployed.
# Kubernetes ingress with Traefik annotations
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: customer-api
annotations:
traefik.ingress.kubernetes.io/router.middlewares: auth-middleware@kubernetescrd
spec:
rules:
- host: api.yourcompany.com
http:
paths:
- path: /customers
pathType: Prefix
backend:
service:
name: customer-service
port:
number: 3000
Traefik handles automatic Let's Encrypt SSL certificates, dynamic routing configuration, and Kubernetes-native service discovery. For teams running entirely on Kubernetes who want a minimal-overhead gateway, Traefik is the cleaner choice.
Service Discovery
Microservices need to find each other dynamically. Services start and stop, scale out and in, and run on different nodes at different times. Static IP configuration does not work in this environment.
Client-side service discovery: each service queries a registry (Consul, etcd) and connects directly to the target service. More control, more implementation work.
Server-side service discovery: the API gateway or load balancer queries the registry on behalf of clients. Clients only need to know the gateway address.
Kubernetes DNS (the most common production approach): Kubernetes automatically creates DNS records for every Service resource. A service named customer-service in namespace production is accessible at customer-service.production.svc.cluster.local. No external registry required.
Circuit Breaker Pattern
In a distributed system, any service can fail at any time. The dangerous failure mode is not a service that fails immediately — it is a service that hangs, responding slowly or not at all. Upstream services waiting for responses hold connections open, building backpressure until the entire request pipeline backs up.
A circuit breaker works like an electrical fuse: when failure rates exceed a threshold, it opens the circuit and stops forwarding requests to the failing service. Instead of waiting for a timeout, callers receive an immediate error or a cached fallback response.
Circuit breaker states:
- Closed: normal operation, requests flow through
- Open: failure threshold exceeded, requests fail immediately without reaching the service
- Half-open: after a recovery timeout, a test request probes the service — if it succeeds, the circuit closes
import CircuitBreaker from 'opossum';
const getCustomerOptions = {
timeout: 3000, // Request timeout in ms
errorThresholdPercentage: 50, // Open circuit when 50% of requests fail
resetTimeout: 30000, // Try again after 30 seconds
};
const customerBreaker = new CircuitBreaker(getCustomer, getCustomerOptions);
customerBreaker.fallback(() => ({
id: 'unknown',
status: 'degraded',
message: 'Customer service temporarily unavailable',
}));
customerBreaker.on('open', () => {
metrics.increment('circuit_breaker.customer_service.open');
logger.warn('Circuit breaker opened: customer service');
});
Without circuit breakers, a single slow service causes cascading failures. With circuit breakers, failures are contained — other services receive fast errors and can serve degraded responses rather than hanging indefinitely.
Saga Pattern for Distributed Transactions
Creating an order in an e-commerce system requires multiple services: persist the order, decrement inventory, charge the payment, send confirmation. Traditional database transactions do not span service boundaries. If the payment charge fails after inventory was decremented, the inventory decrement must be reversed.
The Saga pattern manages distributed transactions through compensating transactions. There are two coordination models:
Orchestration: a central saga orchestrator sends commands to each service in sequence. If any step fails, the orchestrator sends compensation commands to reverse completed steps.
Choreography: services communicate through events. Each service listens for events from preceding services, does its work, and publishes its own completion event. No central coordinator — the workflow emerges from service-to-service event flow.
Orchestration is easier to debug (the workflow is visible in one place). Choreography scales better (no central bottleneck). Most production systems use orchestration for complex transactions and choreography for simpler event flows.
Event-Driven Communication: Kafka vs RabbitMQ
Synchronous request/response is not always the right communication pattern. When a service needs to notify many downstream consumers, or when processing can happen asynchronously, an event bus is more appropriate.
RabbitMQ excels at job queuing and request routing. Messages are acknowledged individually, ensuring exactly-once processing. For task queues, scheduled jobs, and point-to-point messaging, RabbitMQ is simpler to operate than Kafka.
Kafka is built for high-throughput event streaming. It retains messages for a configurable period, allowing consumers to replay event history. Multiple consumer groups can independently process the same stream. For event sourcing, analytics pipelines, and systems where replay capability matters, Kafka is the right choice.
The selection criterion: if you need durable, replayable event history and high throughput, use Kafka. If you need reliable job processing and routing flexibility, use RabbitMQ. Many production systems use both — Kafka for the event log, RabbitMQ for task queues.
Service Mesh: Istio and Linkerd
A service mesh adds a dedicated infrastructure layer for service-to-service communication. A sidecar proxy runs alongside each service container, intercepting all network traffic and enforcing policies transparently.
Istio provides the richest feature set: mutual TLS between all services automatically, fine-grained traffic policies, circuit breaking at the mesh level, request tracing with Zipkin/Jaeger integration, and canary deployment support. The cost is complexity — Istio adds significant operational overhead and has a steep learning curve.
Linkerd is simpler and lighter. It provides automatic mTLS, observability (golden metrics: success rate, request rate, latency), and HTTP/2 and gRPC support out of the box. Teams that want the security and observability benefits of a service mesh without Istio's operational complexity often choose Linkerd.
The key service mesh benefit: your application code does not need to implement mTLS, retry logic, or circuit breaking. The mesh handles it transparently, with uniform policy enforcement across all services regardless of implementation language.
Kubernetes Deployment
A production microservice on Kubernetes uses several resource types working together:
# Deployment: manages pod replicas
apiVersion: apps/v1
kind: Deployment
metadata:
name: customer-service
namespace: production
spec:
replicas: 3
selector:
matchLabels:
app: customer-service
template:
spec:
containers:
- name: customer-service
image: yourregistry/customer-service:1.2.0
ports:
- containerPort: 3000
env:
- name: DATABASE_URL
valueFrom:
secretKeyRef:
name: customer-service-secrets
key: database-url
readinessProbe:
httpGet:
path: /health/ready
port: 3000
initialDelaySeconds: 10
periodSeconds: 5
livenessProbe:
httpGet:
path: /health/live
port: 3000
initialDelaySeconds: 30
periodSeconds: 10
resources:
requests:
cpu: 100m
memory: 128Mi
limits:
cpu: 500m
memory: 512Mi
---
# Service: provides stable network identity
apiVersion: v1
kind: Service
metadata:
name: customer-service
namespace: production
spec:
selector:
app: customer-service
ports:
- port: 3000
targetPort: 3000
The readinessProbe prevents traffic from reaching pods that are not yet ready. The livenessProbe restarts pods that have entered a broken state. Resource limits prevent a runaway service from starving other services on the same node.
Observability: Prometheus, Grafana, and Jaeger
Distributed systems fail in ways that are invisible without structured observability. Three tools cover the essential observability space:
Prometheus scrapes metrics from every service and the API gateway — request rates, error rates, latency percentiles, and custom business metrics. Grafana visualizes these metrics in dashboards and fires alerts when thresholds are crossed.
Jaeger (or Zipkin) provides distributed tracing. A single user request flows through the API gateway, the authentication service, the customer service, and the database — Jaeger tracks the full path, showing which service contributes how many milliseconds to the total latency. This makes root-cause analysis of latency problems tractable.
Key metrics to track at the gateway level:
- Request latency (p50, p95, p99) — the p99 value reveals tail latency that affects real users
- Error rate by service — normalized error rates, not raw counts
- Requests per second by endpoint — capacity planning baseline
- Circuit breaker state — open circuits are an early warning of downstream failures
API Gateway Security
The API gateway is the security perimeter for your microservice cluster. Services behind the gateway should not be accessible from the public internet.
JWT verification at the gateway: services receive pre-verified identity claims and do not need to implement token verification independently.
Rate limiting by tier: different limits for authenticated users, API key clients, and anonymous requests. Per-endpoint limits for expensive operations.
Input validation: reject malformed requests at the gateway before they reach services.
CORS configuration: restrict allowed origins to known client domains. Wildcard CORS (*) is appropriate only for fully public APIs.
Best Practices
- API versioning:
/api/v1/,/api/v2/— never break existing clients with an in-place change - Consistent error responses: all services return the same error shape; the gateway does not need to normalize them
- Idempotency: repeat requests return the same result; use idempotency keys for payment and state-changing operations
- Timeout budgets: every service call has a timeout; no request waits indefinitely
- Graceful shutdown: services complete in-flight requests before shutting down; Kubernetes sends
SIGTERM30 seconds beforeSIGKILL - Health endpoints:
/health/live(is the process alive?) and/health/ready(can the process serve traffic?) are separate checks - Structured logging: JSON logs with correlation IDs enable cross-service log queries in Elasticsearch or Loki
- Distributed tracing propagation: propagate
X-Request-IDand OpenTelemetry trace context through all service calls
Conclusion
API gateway and microservice architecture requires explicit investment in infrastructure that monoliths provide implicitly. Service discovery, circuit breaking, distributed tracing, and service mesh all solve problems that do not exist in a single-process application.
The return on that investment is operational independence: teams deploy their services without coordinating with other teams, services scale independently, and failures are contained rather than cascading. At scale — typically beyond 15 engineers or 1,000 requests per second — the operational benefits exceed the infrastructure cost.
Kong, AWS API Gateway, and Traefik each serve a distinct operational context. Circuit breakers, Saga patterns, and service mesh handle the failure and consistency challenges inherent in distributed systems. Kubernetes provides the deployment and scaling infrastructure. Together, these tools make building reliable, independently deployable services tractable.
Related Articles
MLOps Guide: Taking Machine Learning Models to Production [2026]
87% of machine learning models built by data science teams never reach production. The models work — they pass cross-validation, they score well on holdout sets, they demonstrate genuine predictive value. The problem is not the modeling. The problem is everything that happens between a notebook experiment and a reliable, monitored, production system. MLOps is the discipline that closes that gap. This guide covers the full MLOps stack: maturity levels, tooling choices (MLflow, DVC, Kubeflow
Read More: MLOps Guide: Taking Machine Learning Models to Production [2026]LLM Fine-Tuning Guide: Custom Model Training with LoRA and QLoRA [2026]
General-purpose LLMs are impressive. They can write code, summarize documents, answer questions, and translate between languages with reasonable accuracy. But "reasonable" is not good enough when your application requires consistent output format, domain-specific terminology, a particular tone, or behavior that the base model was never trained to exhibit. That gap is where fine-tuning matters. Fine-tuning updates a model's weights on your specific data, changing how the model behaves — not
Read More: LLM Fine-Tuning Guide: Custom Model Training with LoRA and QLoRA [2026]Computer Vision Applications: Object Detection, OCR, and Industrial AI [2026]
Computer vision has moved well past the research phase. The models are trained, the frameworks are mature, the hardware is accessible, and the use cases are generating measurable returns. What was a specialized capability requiring deep expertise in 2018 is now deployable infrastructure — if you know which component to reach for and where the real complexity lives. This guide covers computer vision applications across industrial, medical, logistics, and document processing domains. It expl
Read More: Computer Vision Applications: Object Detection, OCR, and Industrial AI [2026]
