Skip to content
System Design Lab
Microservice Patterns

Gatekeeper

Put a dedicated, minimal-privilege host in front of trusted services to validate and sanitise every request, so attacks and junk are rejected cheaply at the edge and the services holding secrets are never directly exposed.

Intermediate 4 min read· Updated 2026-11-18

What you will learn

  • Explain the gatekeeper's role and why it holds no secrets.
  • See how cheap edge validation protects backend capacity.
  • Decide what to validate at the gatekeeper and what stays in the service.
  • Avoid making the gatekeeper a bottleneck or a single point of failure.

Before you start

Overview

A bank's vault staff never stand at the front door. Security at the entrance checks IDs and bags; only cleared visitors reach the people with the keys — and the guard at the door has no keys to steal.

A gatekeeper is a separate host or proxy that receives all public traffic. It authenticates, validates and sanitises requests — token signatures, schemas, sizes, allowed methods — and forwards only clean requests over a private network to the trusted host that has the credentials and the data. If the gatekeeper is compromised, the attacker still has no secrets.

Run it

Customers buy while bots send 1,200 invalid requests per second. Compare Purchases failed and Backend busy without (A) and with (B) a gatekeeper.

Loading simulation…

What the gatekeeper checks

CheckExample
AuthenticationVerify JWT signature, issuer, audience and expiry; reject missing tokens.
ShapeJSON schema, maximum body size, allowed content types and methods.
SanitisationStrip unexpected headers, normalise paths, reject path traversal.
AbuseRate limits per client, IP reputation, WAF rules for common injections.

Business authorisation ("may this user refund this order?") stays in the service: it needs domain data the gatekeeper should not have. The backend still validates its inputs — the gatekeeper is one layer of defence in depth, not the only one.

Example

Spring Cloud Gateway as a gatekeeper (no database access, no secrets)
spring:
  security:
    oauth2:
      resourceserver:
        jwt:
          issuer-uri: https://login.example.com/   # verify tokens locally with the issuer's public keys
  cloud:
    gateway:
      server:
        webflux:
          routes:
            - id: payments
              uri: http://payments.internal:8080      # reachable only from the gateway's subnet
              predicates: [ "Path=/api/payments/**", "Method=POST,GET" ]
              filters:
                - name: RequestSize
                  args: { maxSize: 64KB }
                - RemoveRequestHeader=X-Internal-User

Trade-offs

BenefitsCosts
SecuritySmaller attack surface; secrets live only on private hosts.Another component to harden, patch and monitor.
CapacityInvalid traffic is dropped cheaply before it reaches expensive services.The gatekeeper must scale with all traffic, including attacks.
LatencyValidation is fast when done locally (no calls to auth servers).One more network hop for every request.

Production considerations

  • Run several gatekeeper instances across zones; it must not be a single point of failure.
  • Allow traffic to trusted hosts only from the gatekeeper (security groups, network policies, mTLS).
  • Log rejected requests with reasons — they are your first attack signal.
  • Keep the gatekeeper stateless and free of business logic.

Further reading

Related topics