_CORE
AI & Agentic Systems Core Information Systems Cloud & Platform Engineering Data Platform & Integration Security & Compliance QA, Testing & Observability IoT, Automation & Robotics Mobile & Digital Banking & Finance Insurance Public Administration Defense & Security Healthcare Energy & Utilities Telco & Media Manufacturing Logistics & E-commerce Retail & Loyalty
References Technologies Blog Know-how Tools
About Collaboration Careers
CS EN
Let's talk

API Gateway Design — kdy a jak

17. 08. 2021 1 min read intermediate

Architecture Intermediate

API Gateway Design — kdy a jak

API GatewayMicroservicesRouting 3 min read

Jak navrhnout API Gateway pro mikroservisní architekturu. Routing, autentizace, rate limiting a best practices.

Co je API Gateway?

API Gateway je jediný vstupní bod pro všechny klientské požadavky. Funguje jako reverse proxy s routing, autentizací, rate limiting a request transformací.

Architecture

Dva přístupy: Single API Gateway (jeden pro vše) nebo Backend for Frontend (separátní gateway pro web, mobile, IoT).

upstream order_service {
    server order-service:8080;
}
server {
    listen 80;
    location /api/orders {
        proxy_pass http://order_service;
        proxy_set_header X-Request-ID $request_id;
    }
    limit_req_zone $binary_remote_addr zone=api:10m rate=100r/s;
    limit_req zone=api burst=50 nodelay;
}

Autentizace na Gateway

Gateway centralizuje autentizaci. Tokeny se validují na gateway, do služeb se předávají interní identity.

const jwt = require('jsonwebtoken');
function authMiddleware(req, res, next) {
    const token = req.headers.authorization?.split(' ')[1];
    if (!token) return res.status(401).json({ error: 'No token' });
    try {
        const decoded = jwt.verify(token, process.env.JWT_SECRET);
        req.headers['X-User-ID'] = decoded.userId;
        next();
    } catch (err) {
        return res.status(401).json({ error: 'Invalid token' });
    }
}

Populární řešení

  • Kong — open-source, plugin ecosystem
  • Traefik — cloud-native, auto-discovery v K8s
  • AWS API Gateway — managed, integrace s Lambda
  • Envoy — L7 proxy, základ pro service mesh

Summary

API Gateway je kritická komponenta. Nepřetěžujte ho byznys logikou — routing, auth, rate limiting, logging. Vše ostatní patří do služeb.

Need Help with Implementation?

Our team has experience designing and implementing modern architectures. We’re happy to help.

Free Consultation

Share:

CORE SYSTEMS tým

Stavíme core systémy a AI agenty, které drží provoz. 15 let zkušeností s enterprise IT.