Course contentsShow
← Software Engineering
Lesson 1328 of 1,93339. Microservices ArchitectureFree lesson

Gateway Responsibilities and Trade-offs

Deciding what logic belongs in the gateway (auth, rate limiting, routing) versus in services to avoid creating a monolith.

Gateway Responsibilities and Trade-offs

What you'll learn: You'll discover which responsibilities belong in your API Gateway and which should stay in individual services to maintain a healthy microservices architecture.

The Gateway's Identity Crisis

An API Gateway sits at the entry point to your microservices system, and it's tempting to load it with logic. After all, it touches every request! But this creates a critical architectural decision: what truly belongs there versus in your services?

What Lives in the Gateway

The gateway should handle cross-cutting infrastructure concerns that apply uniformly across services:

  • Authentication/Authorization: Verifying tokens and basic permissions
  • Rate limiting: Protecting your system from overload
  • Request routing: Directing traffic to the right service
  • Protocol translation: Converting external HTTP to internal gRPC
  • Basic request/response transformation: Format conversions

What Stays in Services

Keep business logic and domain-specific behavior in your services:

  • Domain validation rules
  • Complex authorization ("Can this user edit this specific resource?")
  • Business workflows
  • Data transformations tied to business rules
  • Service-specific rate limits or policies

The Monolithic Gateway Anti-Pattern

If your gateway starts implementing business logic, you've created a distributed monolith. All services now depend on the gateway for more than just routing—they depend on it for domain decisions. This defeats the purpose of microservices independence.

Think of the gateway as a security guard and traffic director at a building entrance, not the manager making business decisions inside each department.

Trade-offs to Consider

Pushing logic to the gateway improves consistency but creates a deployment bottleneck and couples services. Keeping logic in services preserves independence but may lead to duplication of common patterns.

Key Takeaway: Keep your API Gateway thin and focused on infrastructure concerns—authentication, routing, and protocol handling—while leaving business logic in your services to preserve their independence and avoid recreating a monolith.