Microservice Architecture API Gateway Considerations
Microservice Architecture API Gateway Considerations
Microservice Architecture:
API Gateway Considerations
Introduction ........................................................................................... 3
Security ................................................................................................. 5
Authentication and Authorization .................................................................................. 5
Threat Protection from DDoS ....................................................................................... 6
Secure Communication ................................................................................................ 6
Deployment Considerations ......................................................................................... 6
Orchestration ........................................................................................ 9
Transformation ...................................................................................... 9
Monitoring ............................................................................................. 10
Health Monitoring ......................................................................................................... 10
Traffic and Data Monitoring ........................................................................................... 10
Governance .......................................................................................... 12
Conclusion ............................................................................................ 13
References ............................................................................................ 13
Introduction
Introduction
In today’s extremely competitive business environment, Microservice architecture consists of a suite of independently
customers are more demanding than ever and will abandon deployable, small, modular, and compassable (composable)
a business that is too slow to respond. This has put an onus services. Each service runs a unique process and
on IT to deliver solutions that provide a holistic and uniform communicates through a well-defined, lightweight
experience to the customer, across all business channels. mechanism to serve a business goal. It aligns with the
Microservice architecture has the potential to address this business to deal with changes in agile fashion, matches
business challenge; it is all about achieving speed and safety business changes with agile response, and delivers solutions
at scale and it provides the flexibility to pick and choose in a decentralized manner. In addition to modular services,
technology for implementing a solution. This approach the API gateway and other elements are integral parts of
positions IT as a business partner rather than in a traditional microservice architecture (see figure below).
support role.
Figure 1.
In addition to modular
services, the API
gateway and other
elements are integral
parts of microservice
architecture.
Figure 2.
Demonstration of
how a gateway
typically fits into the
overall microservice
architecture
Security
Security is an important requirement of any enterprise Every API request is authenticated at the gateway layer. On
solution. At a certain point in the architecture, the best behalf of the end user, the application client first grabs an
options available for authentication, authorization, threat access token from the authentication server by presenting
protection, message protection, etc. must be chosen. credentials. This access token is then passed along with the
API request in Authorization HTTP header. The API Gateway
Authentication and Authorization then validates the access token with the authorization
server. The JWT token, which contains the claims for the
Federated identity is the preferred solution for implementing user, is then passed to backend microservices. Backend
authentication and authorization in microservice architecture. microservices then use the information inside the JWT token
Each microservice does not necessarily need to obtain for authorization purpose. The same JWT token is passed
and store users’ credentials in order to authenticate them. along when one microservice communicates with another
Instead, microservices can use an identity management microservice.
system that is already storing a user’s identity to authenticate
the user. This approach allows the decoupling of the The flow above has the potential to be a “confused deputy
authentication and authorization functions. It also makes it problem,” as every microservice is relying on the API
easier to centralize these two functions, to avoid a situation Gateway for authentication. Ideally, every microservice should
where every service must manage a set of credentials for authenticate the token as received from its caller (gateway
every user. or microservice). There is a trade-off between security and
performance. The above mentioned architecture leans
There are three major protocols for federated identity: toward performance, as there are other mechanisms to
OpenID, SAML, and OAuth. The figure below shows the mitigate the security risk.
security architecture using OAuth2.0.
Figure 3.
Security architecture
using OAuth2.o
The microservice architecture is part of the overall IT • Black list / White list IP addresses, if you can definitely
infrastructure for an enterprise. If the enterprise IT is cloud identify valid and invalid end users of your APIs
focused, then you should use a well-known cloud based
authorization server, like Azure Active Directory or AWS • Limiting the connections to backend microservices
IAM, which can also be integrated with on premise identity
stores, like active directory. An open-source server like • Blocking requests:
IdentityServer4 makes it possible to implement your own o that seem to target a specific API
authorization server and integrate with existing identity stores. o that have a User-Agent header, set to a value that
does not correspond to normal client traffic
o that have a referrer header, set to a value that can
Threat Protection from DDoS be associated with an attack
o that have other headers with values that can be
Most of the API Gateway provides (either integral or add-
associated with an attack
on packages) features that can handle DDoS attacks,
by regulating and controlling the traffic as it proceeds to
backend microservices. Consider configuring the following
Secure Communication
traffic regulating parameters for the API Gateway:
It is always desirable to have SSL/TLS compliant endpoints
at the API Gateway, as well as at the microservices layer, to
• Limiting the rate of requests: Maximum number
safeguard against man-in-middle attacks, and bi-directional
of requests an API can access within a given time
encryption of message data to protect against tampering.
frame, based on rate limiting approach. Some of the
approaches are Authenticated User, Request Origin,
If you are dealing with a number of certificates, then
Authenticated User, and Request Origin. For example,
managing those becomes a huge administrative burden.
you might decide that an API may be accessed only
There are solutions like letsencrypt.org, an AWS certificate
once a day, by an authenticated user from a specific
manager, which makes it possible to transparently issue or
mobile application.
revoke certificates.
Figure 4.
Service registration and
discovery
Service Discovery
The number and location of service instances is dynamic. Server-side discovery is preferred for various reasons:
Consequently, your client code needs to use a more
elaborate service discovery mechanism. There are two main • It removes the discovery burden from the client so it can
service discovery patterns: client-side discovery and server- focus on business functions.
side discovery, as shown in the figure below.
• If you have multiple clients, then you need to code and
maintain the discovery code for each client.
Figure 5.
There are two main
service discovery
patterns: client-side
discovery and server-
side discovery.
Orchestration Transformation
It is often necessary to orchestrate across multiple fine- Often microservices have to deal with different clients
grained microservices to accomplish a business use case. on the front end. They have different needs, from both
As shown in the figure below, there are two options for protocol (SOAP, REST, JSON,and XML) and data
implementing the orchestration: using the API Gateway as perspective. Similarly, when you are moving from monolith to
the orchestration layer or coding orchestration in a separate microservices, backend services may understand different
microservice. protocols (SOAP, REST, AMQP etc.).
You should avoid orchestration at the gateway layer. It The API Gateway provides a place for data transformation,
violates the single responsibility principle and, in the case of where messages can be translated between backend, API,
scaling the API, you will have to scale the gateway along with and app formats and protocols. The gateway provides a
orchestrated microservices. Some of the API Gateways have central data transformation point through which all traffic is
little to no capability for orchestration. translated for:
Figure 6.
There are two options
for implementing
orchestration: using
the API Gateway as the
orchestration layer or
coding orchestration in
a separate microservice.
Monitoring
Being a single entry point into the system, all of the traffic Traffic and Data Monitoring
in and out of the system passes through the API Gateway,
so monitoring the gateway is critical. This provides an Analyzing the traffic data will help you to take proactive
opportunity to capture the information about data flow, which measures, to ensure smooth working of the software
becomes an input for IT administration and IT policies. systems and shape up the IT policies. You should consider
monitoring the following basic metrics:
Health Monitoring
• Number of requests per API
Health monitoring is done to make sure the gateway is up • Request categorization by criteria (for example, remote-
and running. For health monitoring, it is recommended to host)
capture: • Performance statistics
• Successful and exception messages
• System status and health (CPU, Memory, Thread usage) • Blocked messages breaching gateway policies
• Network connectivity
• Security alerts You should also regularly analyze the traffic over long range
• Backups and recovery period to be able to identify predictable traffic levels and be
• Maintenance of logs ready for any surge.
The API Gateway does not impose any special requirements The API Gateway also ensures zero downtime by
on load balancers. Loads are balanced on a number of implementing configuration deployment in a rolling fashion.
characteristics including the response time or system load. This means, while each API Gateway instance in the cluster
The execution of API Gateway policies is stateless, and or group takes a few seconds to update its configuration, it
the route through which a message takes on a particular stops serving new requests, but all existing in-flight requests
system has no bearing on its processing. Some items like are honored. Meanwhile, the rest of the cluster or group
caches and counters, which are held on a distributed cache, can still receive new requests. The load balancer ensures
are updated on a per-message basis. This helps the API that requests are pushed to the nodes that are still receiving
Gateway to operate successfully in both sticky and non- requests.
sticky modes.
Figure 7.
Load balancing and
scaling
High Availability can be maintained using either of these Tracking the life cycle of APIs:
options: Active/Active, Active/Standby, or Active/Active
Systems. These are described as follows: • Handling routing, blocking, and processing
• Understanding the API utilization and raising the alerts/
• Active/Standby: System is turned off alarms in case usage crosses the threshold
• Active/Passive: System is operational but not containing • Traffic throttling, smoothing, and load balancing
state • Rate limiting per-API usage
• Active/Active: System is fully operational and with current • API versioning
system state • Schema versioning for input/ output request parameters
• To achieve maximum availability, API Gateway should be • Defining the standards for API definitions (example:
used in Active/ Active for each production API Gateway Swagger)
• Keyword tags used to categorize APIs
• Proper traffic analysis, to limit traffic to backend services, • Conformance to REST API design guidelines
to protect against message flooding. This is particularly
important with legacy systems that have been recently
service-enabled. Legacy systems may not have been
designed for the traffic patterns to which they are now
subjected.
Conclusion
The API Gateway is the essential component of
microservices architecture. It helps to: 1741 Technology Dr.
San Jose, CA 95110
• Decouple consumers of the services from backend
services +1.408.273.8900
• Implement policies in one place info@globallogic.com
www.globallogic.com
• Achieve reusability
• Monitor the entire technology platform performance 2017 GlobalLogic, Inc.
• Enable easy scaling of services All Rights Reserved
References
• Pattern: API Gateway / Backend for Front-End
(Microservices.io)
• Building Microservices: Using an API Gateway (NGINX)
• Enabling Microservice Architecture with Middleware
(WSO2 Blog)
• Welcome to IdentityServer4 (IdentityServer4)
• Oracle® Fusion Middleware Part 1. API Gateway
administration (Oracle)