Microservices

Article 08: Gateway Filters & Centralized Routing

By Utility Zone · 2026-01-28T11:08:35.875394

1. Objective

Learn how to use filters in API Gateway for logging, authentication, and request modification.

2. Key Concepts

  • Global filters
  • Route-specific filters
  • Pre and Post filters

3. Why Filters Matter

Common needs:

  • Logging
  • Authentication
  • Header modification
  • Rate limiting

4. Simple Global Filter Example

@Component
public class LoggingFilter implements GlobalFilter {

    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        System.out.println("Request Path: " + exchange.getRequest().getPath());
        return chain.filter(exchange);
    }
}

5. Route-Specific Filter

filters:
  - AddRequestHeader=X-Request-Source, Gateway

6. Centralized Routing Benefits

  • Easy changes
  • No client impact
  • Versioning support

7. Common Mistakes

  • Heavy logic in filters
  • Ignoring performance impact
  • No fallback handling

8. Interview Notes

  • Filters run before/after routing
  • Gateway is not a replacement for service logic

9. Summary

Filters make API Gateway powerful and flexible.

10. What’s Next

Add centralized configuration using Spring Cloud Config.