Sitemap
Neil McKinnon

Neil McKinnon

Software Consultant, Architect, Developer, LEAN/DevOps, and Leadership enthusiast.

GATEWAYS

6 min readJun 27, 2020

--

Much of my career has been shaped by Tiered Architectures. In this model, each tier encapsulates a specific responsibility that can be slotted into place between other tiers to build something more advanced. It’s an extremely flexible model, ensuring responsibilities remain cohesive (unpolluted) and comprehensible.

Consider the OSI networking reference model. Individually, each network layer doesn’t provide much value, but when combined, form something extremely powerful. The Three-Tiered architecture (and Model-View-Controller (MVC) pattern) offers another example of distinct tiers — it splits an application into distinct tiers (presentation, business, and database) — and has been widely adopted.

TERMINOLOGY

I’ve opted to use the umbrella term “gateway” here to define both API Gateways and Edge Services. Both are used to funnel requests through, prior to a deeper interaction with an internal system.

Gateways play a key role in a tiered architecture (tiered architectures never really died, — even with the advent of Microservices or Cloud services such as Serverless — they just became less prominent). They have some distinct advantages, including:

  • (Logically) There’s only one of them. Common responsibilities are encapsulated in one place, rather than strewn liberally across an internal system (although Microservice purists might disagree on the shared responsibility point).
  • High Reusability and Flexibility, due to low Assumptions and its decoupled nature.
  • Protects sensitive parts of an internal system from pollution. For instance, internal integrations between services can be more challenging if the security model becomes a hindrance. Encapsulating that responsibility elsewhere can simplify that integration.
  • High comprehensibility. It’s easy to identify where certain responsibilities lie.

OVERLOADING RESPONSIBILITIES

Collecting disparate responsibilities in a confined area of a system can create a range of problems, including tight-coupling, complexity, Assumptions, alongside Extensibility, Reuse, and Evolvability challenges. Breaking them out allows them to be better managed.

Press enter or click to view image in full size

Gateways are commonly used to:

  • Authorise (or deny) incoming requests, such as by verifying a JWT (JSON Web Token), or comparing hashes (e.g. HMAC).
  • Capture all interactions with the internal system for Non-Repudiation.
  • Inject system-level tracing for debugging and metrics capture.
  • Rate limiting (throttling). We can protect a system from being flooded by limiting how many users access it. Whilst this may seem counterintuitive, it’s preferable to allow some users in, than being forced to reject them all.
  • Decisions and routing for Canary Releases and Feature Flags.

The diagram below presents some typical actions of a Gateway.

TAILORED UTILITIES

Gateways can also be a good place to hold “utility” features that require tailoring for different customers.

Consider the following case. Let’s say you offer services through APIs to a range of corporate customers. Those corporate customers often have differing security expectations and therefore may dictate their preferred security model to you. Sounds unlikely, yet many smaller businesses don’t hold sway over their large corporate counterparts, who can often dictate the terms of the contract. In these cases, reasoned arguments about technical purity and consistency will fall on deaf ears as the drum beats to dollars. You’re forced to support multiple security models to satisfy all customer needs.

These types of bespoke behaviours fit poorly into an internal system — ensuring it remains agnostic to these behaviours is vital to reduce complexity and Assumptions, thus increasing its Flexibility, Reuse, and Evolvability — but you still need to support those behaviours somewhere. One solution is to encapsulate these behaviours within a Gateway, using (canary) Feature Flags to route traffic to the appropriate tailored security model before pushing it deeper into the internal system.

Gateways can — of course — have some disadvantages:

  1. Scalability. The Gateway should be just as capable (or more so) than the internal system it protects. You don’t want the embarrassment (or worse) of talking up your highly scalable (internal) system, if the only way to access it is through a poorly performing gateway.
  2. It could be a potential Single Point of Failure. If the Gateway fails (either due to a miscreant release or a runtime error) then we may find our entire system is unavailable.
  3. Availability of the whole system is measured by both the internal system, and the Gateway’s availability. This is Availability in Series. As such, we measure the overall availability by GAIA (where GA is the gateway’s availability and IA is the internal system’s availability). A sobering thought but we find that the overall availability is lowered than if we were to solely expose the internal system.
  4. The overloading of responsibilities. It’s important that we limit the smarts held within the Gateway and keep it agnostic to domain-specific internal system needs. We’re not trying to build a monolithic Gateway or ESB. Gateways should be lightweight and cohesive, and built for common (reusable) responsibilities.
  5. Atomic Releases. All or nothing. There may be cases where you want the flexibility to choose when you upgrade parts of your internal system (e.g. you may have an impending delivery date and any unnecessary regression testing will put it at risk). As all internal functionality first comes through a centralised Gateway, we may find the scope of change undesirable. The secondary effects of this may cause Change Friction and hinder Evolvability.

REAL-WORLD EXAMPLE

Let’s now turn to look at an example where a Gateway could have been quite useful.

Consider a system consisting mainly of a suite of Microservices. Embedded within each microservice lives an Assumption about its security mechanism — JWT should be used by all callers. Doesn’t seem too bad, but let’s say that this security model is only accessible through a UI authentication mechanism and not to service-to-service interactions. That’s ok whilst the UI is the only consumer, but not when we find other services want to talk to one another.

The Assumption (JWT) embedded within these services limits its reuse potential — it isn’t built to function with alternative security mechanisms. (Service) Consumers would either have to change their model to use JWT, or we’d need to embed another security model into each microservice; not only increasing complexity but also introducing a significant development and regression cost. Additionally, we’d be reworking each microservice again whenever a further security mechanism needed to be supported.

This scenario provides ideal stomping ground for an indirectional layer (Indirection) such as a Gateway. If a gateway handles all security needs, we can manage that behaviour centrally, allowing quicker change and extension, and minimising pollution in the internal system.

SUMMARY

Gateways are extremely versatile and offer the following benefits:

  • Flexibility, Extensibility, and Reusability. We can easily change a behaviour or add new ones and have it take effect across the entirety of our solution.
  • Change once semantics, since there’s (logically) only one of them.
  • They protect sensitive parts of an internal system from (unnecessary) pollution. This can also increase reuse.
  • High comprehensibility. It’s easy to find these behaviours and to articulate where they are executed.

However, you should also be aware of some of their disadvantages, including the Availability ramifications (Availability in Series), and (due to its intent) that it can become a Single Point of Failure.

Get Neil McKinnon’s stories in your inbox

Join Medium for free to get updates from this writer.

Whilst it’s tempting to circumvent the Gateway when two internal services wish to interact, be careful that you’re not circumventing an important behaviour (in the gateway) that will catch you later on (such as when you need to publicly expose one of those services and find that external consumers get a different experience to internal consumers — Eat Your Own Dog Food).

Most Cloud providers offer their own (API) Gateways. Amazon AWS has one (aptly named API Gateway), as do Microsoft and Google. These gateway services often have extremely good integration with other Cloud services (at least with their own) with a focus on Integrability and TTM.

FURTHER CONSIDERATIONS

  • Availability in Series
  • Eat Your Own Dog Food
  • Assumptions
  • Microservices
  • Cloud
  • Single Point of Failure
  • Non-Repudiation
  • Canary Releases
  • Feature Flags
  • Indirection
  • Change Friction
  • Serverless

--

--

Neil McKinnon
Neil McKinnon

Written by Neil McKinnon

Software Consultant, Architect, Developer, LEAN/DevOps, and Leadership enthusiast.