API Gateways Are Going Through an Identity Crisis
What exactly are API gateways?
Join the DZone community and get the full member experience.Join For Free
api gateways are going through a bit of an identity crisis these days.
- are they centralized, shared resources that facilitate the exposure and governance of apis to external entities?
- are they cluster ingress sentries that tightly control what user traffic comes into the cluster or leaves it?
- or are they some kind of api coalescing glue to more succinctly express an api depending on the type of clients it may have?
- and of course the elephant in the room and a question i often hear: “does service mesh make api gateway obsolete?”
with how fast technology moves, and how quickly the industry shuffles through technology and architecture patterns, you’d be forgiven to be thinking “all of this is making my head spin.” in this post, i’m hoping to boil down the different identities of an “api gateway,” clarify what groups in the organization may use an api gateway (the problems they’re trying to solve), and re-focus on first principles. ideally, by the end of this post, you’ll better understand the role of api infrastructure at these different levels for different teams and how to get the most value out of each level.
before we dive in, let’s be very clear about the term api.
my definition of api
an explicitly and purposefully defined interface designed to be invoked over a network that enables software developers to get programmatic access to data and functionality within an organization in a controlled and comfortable way.
these interfaces abstract the details of the technology infrastructure that implements them. for these designed network endpoints, we expect some level of documentation, usage guidance, stability, and backwards compatibility.
in contrast, just because we can communicate with another piece of software over the network does not necessarily mean that remote endpoint is an api by this definition. lots of systems communicate with each other, however, that communication happens more haphazardly and trades off immediacy with coupling and other factors.
we create apis to provide a thoughtful abstraction over parts of the business to enable both new business functionality as well as serendipitous innovation.
first up on the list when talking about api gateways is api management.
a lot of folks think about api gateways in terms of api management. this is fair. but let’s take a quick look at what exactly this gateway does.
with api management , we are looking to solve the problem of “when we wish to expose existing apis for others to consume,” how do we track who uses these apis, enforce policies about who’s allowed to use them, establish security flows to authenticate and authorize permissible use, and build a catalog of services that can be used at design time to promote api usage and lay the foundation for effective governance.
we want to solve the problem of “we have these existing, curated apis that we want to share with others but share them on our terms. ”
api management also does nice things to allow users (potential api consumers) to self-service, sign up to different plans for api consumption (think: numbers of calls per user per endpoint within a given time frame for a specified price point). the piece of infrastructure where we are able to enforce these kinds of management functions is the gateway through which our api traffic traverses. at this point, we can enforce things like authentication, rate limiting, metrics collection, other policy enforcement, el. al.
examples of api management software that leverages an api gateway:
at this level, we are thinking in terms of apis (as defined above) and how best to manage and allow access to them. we are not thinking in terms of servers, hosts, ports, containers, or even services (another poorly defined word, but stick with me!).
api management (and thus their corresponding gateways) are usually implemented as tightly controlled shared infrastructure owned by either a “platform team,” “integration team,” or other api infrastructure teams.
one thing to note: we want to be careful not to allow any business logic into this layer. as mentioned in the previous paragraph, api management is shared infrastructure, but since our api traffic traverses it, it has the tendency to re-create the “all-knowing, all-being” (think enterprise service bus) governance gate through which we must all coordinate to make changes to our services. in theory, this sounds great. in practice, this can end up being an organizational bottleneck. see this post for more: application network functions with esbs, api management, and now… service mesh?
to build and implement apis, we focus on things like code, data, productivity frameworks, and so on. but for any of these things to provide value, they must be tested, deployed into production and monitored. as we start deploying to cloud-native platforms, we start thinking in terms of deployments, containers, services, hosts, ports, etc. and building our application to live in this environment. we’re probably crafting workflows (ci) and pipelines (cd) to take advantage of the cloud platform to move quickly, make changes, get them in front of customers, and so on.
in this environment, we may build and maintain multiple clusters to host our applications and need some way of accessing the applications and services inside those clusters. think, for example, in terms of kubernetes. we may use a kubernetes ingress controller to allow access into the kubernetes cluster (everything else in the cluster is not accessible from the outside). that way we keep very tight control over what traffic may enter (or even leave) our cluster with well-defined entry points like domain/virtual hosts, ports, protocols, et. al.
at this level, we may want some sort of “ingress gateway” to be the traffic sentry for allowing requests and messages into the cluster. at this level, you’re thinking more in terms of “i have this service in my cluster, i need people outside the cluster to be able to invoke it”. this could be a service (exposing an api), an existing monolith, a grpc service, a cache, a message queue, a database, etc. some folks have chosen to call this an api gateway, and some of them might actually do more than traffic ingress/egress, but the point is the problems at this level exist at the cluster-operations level. as we tend to deploy more clusters (vs a single, highly multi-tenant cluster) we end up with more ingress points and the need for those to interact with each other.
examples of these types of ingress implementations include:
- envoy proxy and projects that build upon it including:
- including openshift’s router
this level of cluster ingress controller is operated by the platform team, however, this piece of infrastructure is often associated with a more decentralized, self-service workflow (as you would expect from a cloud-native platform). see the “gitops” workflow as described by the good folks at weaveworks .
api gateway pattern
another expansion on the term “api gateway” is the one i typically think of when i hear the term and that’s the one that most closely resembles the api gateway pattern . chris richardson does an excellent job of covering this usage in his book “microservices patterns” in chapter 8. i highly recommend getting this book for this and other microservices-patterns education. a quicker tour can be seen on his microservices.io site on api gateway pattern . in short, the api-gateway pattern is about curating an api for more optimal usage by different classes of consumers. this curation involves a level of api indirection. another term you may hear that represents the api gateway pattern is “backend for front-ends” where “front-end” can be literal front-ends (uis), mobile clients, iot clients, or even other service/application developers.
in the api gateway pattern, we are explicitly simplifying the calling of a group of apis to emulate a cohesive api for an “application” for a specific set of users, clients, or consumers. recall that as we use microservices to build our systems, the notion of “application” kind of disappears. the api gateway pattern helps to restore this notion. the key here is the api gateway, when it’s implemented, becomes the api for clients and applications and is responsible for communicating with any backend apis and other application network endpoints (those that don’t meet the aforementioned definition of api).
unlike the ingress controller from the previous section, this api gateway is much closer to the developers view of the world and is less concentrated on what ports or services are exposed for outside-the-cluster consumption. this “api gateway” is also different from the api management worldview where we are managing existing apis . this api gateway mashes up calls to backends that may expose apis, but may also talk to things less described as apis such as rpc calls to legacy systems, calls with protocols that don’t fit the nice semblance of “rest” such as hacked together json over http, grpc, soap, graphql, websockets, and message queues. this type of gateway may also be called upon to do message-level transformation, complex routing, network resilience/fallbacks, and aggregation of responses.
if you’re familiar with the richardson maturity model of rest apis , an api gateway implementing the api gateway pattern would be called upon to integrate much more of the level 0 requests (and everything in between) than the level 1 - 3 implementations.
these types of gateway implementations still need to solve for things like rate-limiting, authentication/authorizations, circuit breaking, metrics collection, traffic routing, and the like. these types of gateways can be used at the edge of your cluster as a cluster ingress controller or deep within your cluster as application gateways.
examples of this type of api gateway include:
this type of gateway can also be built using more general purpose programming or integration languages/frameworks like:
since this type of api gateway is so closely related to the development of applications and services, we’d expect developers to be involved in helping to specify the apis exposed by the api gateways, understanding any of the mashup logic involved, as well as need the ability to quickly test and make changes to this api infrastructure. we also expect operations or sre to have some opinions about security, resiliency, and observability configuration for the api gateway. this level of infrastructure must also fit into the evolving, on-demand, self-service developer workflow. again see the gitops model for more on that.
bring on the service mesh
part of operating a services architecture on cloud infrastructure includes the difficulty of building the right level of observability and control into the network. in previous iterations of solving for this problem, we used application libraries and hopeful developer governance to achieve this . however, at scale and across a polyglot environment, the emergence of service-mesh technology lends a better solution . service mesh brings the following capabilities to a platform and its constituent services by transparently implementing
- service to service (ie, east-west traffic) resilience
- security including end-user auth verification, mutual tls, service-to-service rbac/abac
- black-box service observability (focused on network communication) for things like requests/second, request latency, request failures, circuit-breaking events, distributed tracing, etc
- service-to-service rate limiting, quota enforcement, etc
the astute reader will recognize that there appears to be some overlap in functionality with an api gateway and service mesh . the goal of the service mesh is to solve these problems generically for any service/application by doing so transparently at l7. in other words, the service mesh wishes to blend into the service (without actually being coded into the service’s code). on the other hand, api gateways live above the service mesh and with the applications (l8?). service mesh brings value to the flow of requests between services, hosts, ports, protocols, etc (east/west traffic). they can also provide basic cluster ingress capabilities to bring some of this functionality to the north/south traffic. however, this should not be confused with the capabilities that the api gateway can bring to north/south traffic (as in north/south to the cluster and north/south to an application or group of applications).
service mesh and api gateway overlap in functionality in some areas but are complementary in that they live at different levels and solve different problems. the ideal solution would be to plug and play each of the components (api management, api gateway, service mesh) into your solution with nice boundaries between the components as you need them (or exclude them as you don’t need them). equally important is finding the implementation of these tools that fit into your decentralized developer and operations workflow . even though there is confusion in the terms and identities of these different components, we should rely on first principles and understand where in our architecture these components bring value and how they can exist independently and co-exist complementarity.
Opinions expressed by DZone contributors are their own.