Why Service Gateways Are Essential for Microservices Architecture

The article explains what a service gateway is, why it’s needed to centralize cross‑cutting concerns like authentication, how it improves deployment and jar size, outlines its core functions and workflow, and presents a Java‑based technical stack for building a lightweight gateway.

ITFLY8 Architecture Home
ITFLY8 Architecture Home
ITFLY8 Architecture Home
Why Service Gateways Are Essential for Microservices Architecture

What Is a Service Gateway

服务网关 = 路由转发 + 过滤器

Routing: receives all external requests and forwards them to backend microservices.

Filters: implement cross‑cutting functions such as authentication, rate limiting, and monitoring (routing itself is also realized via filters).

Why a Service Gateway Is Needed

Cross‑cutting functions like authentication can be placed in three locations:

Implemented separately in each service.

Implemented in a shared common service that all microservices depend on.

Implemented in a pre‑filter of the service gateway.

The first approach is rarely used due to obvious drawbacks. The second reduces code duplication but introduces two problems:

Each service’s JAR size grows because the same authentication code is packaged repeatedly, which is undesirable for Docker images.

Upgrading the shared service becomes difficult; any change to authentication logic requires recompiling and redeploying all dependent services.

A service gateway solves these issues by moving authentication logic into gateway filters, keeping backend services free of authentication code, avoiding JAR bloat, and allowing authentication changes by updating only the gateway.

Service Gateway Technical Selection

After introducing a service gateway, the microservice architecture consists of three parts: the gateway, an open‑service, and individual services.

Overall Process

The gateway, open‑service, and services register themselves with a service registry at startup.

When a user sends a request, it goes directly to the gateway, which performs intelligent routing (including service discovery and load balancing) to the open‑service, applying authentication, monitoring, and rate limiting.

The open‑service aggregates responses from internal services, returns the result to the gateway, which then forwards it to the user.

Considerations When Adding a Gateway

Introducing a gateway adds an extra hop, slightly reducing performance, though the impact is usually small because gateway machines are powerful and internal network latency is low.

Gateway single‑point‑of‑failure risk: you can place an Nginx instance in front of the gateway to provide high‑availability; however, this adds another hop, so the best practice is to deploy the gateway on a robust machine and scale it horizontally.

Keep the gateway lightweight.

Basic Functions of a Service Gateway

Intelligent routing: forwards external requests to the open‑service.

Authentication: validates user requests to the open‑service (internal service‑to‑service calls are not authenticated by the gateway).

API monitoring: tracks requests passing through the gateway and its own performance metrics (e.g., GC).

Rate limiting: works together with monitoring to limit traffic.

Unified API logging: records entry and exit logs similar to an aspect.

Additional capabilities such as A/B testing can also be implemented, though the split‑traffic engine is usually better placed in the open‑service.

Technology Stack

Programming language: Java + Groovy (Groovy allows dynamic addition of filters without restarting the gateway).

Microservice framework: Spring Boot.

Gateway component: Netflix Zuul.

Service registry: Consul.

Authentication: JWT.

API monitoring: Prometheus + Grafana.

Unified logging: Logback + ELK stack.

Load testing: JMeter.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

microservicesZuulservice gateway
ITFLY8 Architecture Home
Written by

ITFLY8 Architecture Home

ITFLY8 Architecture Home - focused on architecture knowledge sharing and exchange, covering project management and product design. Includes large-scale distributed website architecture (high performance, high availability, caching, message queues...), design patterns, architecture patterns, big data, project management (SCRUM, PMP, Prince2), product design, and more.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.