esc
  • WorkflowsPages
  • Case studiesPages
  • Machine Learning FoundationsLearn
  • AI EngineeringLearn
  • AI Guardrails & Red TeamingLearn
  • UI/UXLearn
  • Design SystemsLearn
  • Production System DesignLearn
  • Book a callContact
  • Download ResumeContact
Let’s talk

I’ll build the agent for it.

Gatekeeper: A Guard Host That Checks Every Request Before the Real Work

A gatekeeper is a public-facing host that validates and cleans each request, so the trusted backend that holds the secrets never faces the internet directly.

In short

A gatekeeper is a public-facing host that validates and cleans each request, so the trusted backend that holds the secrets never faces the internet directly.

11 min readFree

What you will learn

This lesson explains the Gatekeeper pattern. You will learn why it splits one app into a public guard and a protected worker, how a request travels between the two, and when the extra layer is worth its cost. A worked example follows a bank transfer, and a short Python sample shows the same flow in miniature.

Microsoft's catalog of cloud patterns summarizes the idea as a dedicated host that checks and cleans requests before sending them on to protected servers. Each part of that short summary is explained below.

Key words

Gatekeeper
A public-facing service that checks every request and passes only the safe ones on to the protected part of the system.
Client
Any program that sends requests, such as a phone app or a web browser.
Trusted host
The protected server or service that does the real work and holds the keys to data.
Validate
Check that a request follows the rules, such as having a valid login and the right input format.
Sanitize
Clean a request by removing or rejecting unexpected or unsafe content.
Session token
A secret string that proves a user has already signed in.
Endpoint
A web address where other programs send requests.
Credentials
Passwords, keys, or tokens that let a program open a database or use a service.
Compromise
When an attacker gains control of a system that they should not control.
Private network
A network that only your own machines can reach, not the open internet.
Latency
The delay between sending a request and getting the reply.
Single point of failure
One part whose failure stops the whole system from working.

Why is direct exposure risky?

Many services publish endpoints. Public endpoints sit on the open internet, which is a network you do not control. The code behind them often does several jobs at once. It checks who is calling, checks the input, and reads or writes data using stored keys.

That mix is the risk. If an attacker breaks into that one program, they inherit everything it can do. They may reach stored keys, sensitive records, and other internal services. The gatekeeper pattern tries to shrink that damage by splitting the public job from the powerful job.

What is separation of duties?

The core idea is separation of duties. Each part gets only the jobs and powers it needs, so a break-in at one part gains little. The pattern names two parts.

  • The gatekeeper

    This is the public-facing part, and its power is deliberately small. It checks identity, checks the shape of inputs, and cleans requests. It is meant to stay lightweight and focused on validation and sanitization, not on the application's processing.

  • The trusted host

    This is the protected part. It accesses services and storage. It does the real processing, and nothing outside should reach it directly. It should expose only internal or protected endpoints, and connect only to the gatekeeper.

  • Why the split helps

    The gatekeeper does not access the credentials or keys that the trusted host uses. Risks and exposure are reduced because the gatekeeper does not have the credentials or keys that the trusted host uses. If an attacker takes over the public part, the keys to the database are still missing.

What is limited privilege?

Privilege means the rights a program or account has. Running the gatekeeper in limited-privilege mode means its account can do only its narrow job. The rest of the application runs with the full rights it needs to reach storage and services. The usual setup runs the gatekeeper and the trusted nodes in separate hosted services or virtual machines. The gatekeeper should be run with limited privilege.

How does a request flow?

Every request follows the same route. Only the gatekeeper faces the client, and only clean requests cross into the protected zone.

  1. 1

    The client calls the public door

    A phone app sends its request to the gatekeeper's public address. Only the gatekeeper should connect to the trusted hosts, and those hosts should expose only internal or protected endpoints. The client never has a reason to talk to the protected side.

  2. 2

    The gatekeeper runs its checks

    It checks the caller's session token, looks at the input format, and can apply rate limits, which are caps on how many requests one caller may send in a set time. Other checks may include authentication (proving who the caller is), authorization (deciding what that caller may do), other sanitization steps, or checks for specific metadata in requests.

  3. 3

    Bad requests stop at the door

    The gatekeeper validates all requests and rejects any that fail the validation requirements. A rejected request never reaches the protected host.

  4. 4

    Good requests go inward as a clean copy

    Validation typically means the gatekeeper cleans the request content before it passes that content to the trusted host. The gatekeeper then sends the cleaned copy over an internal link.

  5. 5

    The trusted host does the work

    It runs the business rules, touches the database, and builds the reply. The trusted hosts might need to perform extra request validation, but the gatekeeper should perform the core validation.

  6. 6

    The reply goes back out

    The answer travels back through the gatekeeper to the client. Nothing else is published on the way back.

Isolating the internal channel

The link between the two parts is where many designs go wrong. A good setup makes that link hard to reach from outside and confirms who is on each end.

  • Private network

    Put the two parts on a network that only your own machines can reach. Place the gatekeeper and the trusted back end on separate compute boundaries, and keep back-end endpoints private.

  • Restricted endpoints

    The trusted host publishes only the few internal doors the gatekeeper needs. Every other door stays closed to outsiders and to the gatekeeper alike.

  • Separate credentials

    The gatekeeper should not hold the database password. Its login to the trusted host should be its own, with limited rights. The gatekeeper does not use the credentials or keys that the trusted host uses to reach storage and services.

Tip

Encrypt the internal link with HTTPS or TLS (the standard method that scrambles traffic so others cannot read it) where your platform allows it. Some hosting setups do not offer HTTPS on internal endpoints, so check that before you build. The Azure guidance asks for a secure channel between the two parts where possible.

Worked example: a bank transfer

Picture an online banking web app. A signed-in user fills in a form with an amount and a receiving account, then presses the transfer button. The app uses the gatekeeper pattern in the following way.

  1. 1

    The app sends the form

    The browser sends the transfer details to the public gatekeeper service. The request carries the session token from the user's login.

  2. 2

    The gatekeeper checks the token

    It confirms that the token is genuine and still valid. A forged or expired token is rejected here, so the payments service never sees it.

  3. 3

    The gatekeeper checks the input

    It confirms that the amount contains digits only and that the account number has the expected shape. It also trims stray spaces from the receiver field.

  4. 4

    Only the cleaned request moves on

    The gatekeeper builds a new copy that holds just the expected fields. It sends that copy to the internal payments service over the private network.

  5. 5

    The payments service does the real work

    This internal service is the only part that holds the database credentials. It checks the balance, moves the money, and records the result.

  6. 6

    The reply returns

    The result passes back through the gatekeeper to the app, which then shows the user a confirmation or an error message.

The sample below copies the same flow in miniature. The gatekeeper function checks the token and the amount, then calls the payments function. In a real system, only the payments side would hold database access.

Python
TOKENS = {'token-abc': 'alice'}

def payments_service(clean):
    # Only this internal service would hold database credentials.
    return 'paid %d from %s to %s' % (clean['amount'], clean['user'], clean['to'])

def gatekeeper(request):
    user = TOKENS.get(request.get('token', ''))
    if user is None:
        return 'rejected: bad session'
    amount = request.get('amount', '')
    if not amount.isdigit():
        return 'rejected: amount must be digits'
    clean = {'user': user, 'amount': int(amount), 'to': request['to'].strip()}
    return payments_service(clean)

print(gatekeeper({'token': 'token-abc', 'amount': '250', 'to': ' bob '}))
print(gatekeeper({'token': 'wrong', 'amount': '250', 'to': 'bob'}))
print(gatekeeper({'token': 'token-abc', 'amount': '2x', 'to': 'bob'}))

Output

paid 250 from alice to bob
rejected: bad session
rejected: amount must be digits

Read the output. The first request passes every check and reaches the payments step. The other two stop at the gatekeeper, so the payments code never runs for them. That is the pattern in one picture: the door checks, and only clean work goes inside.

What does the extra layer cost?

A gatekeeper buys safety with effort. Weigh these costs before you add one.

  • Extra delay

    Each request takes one more hop and one more round of checks. Because the gatekeeper adds a step to the routing, it may increase latency.

  • One more part to run

    You must deploy, patch, monitor, and scale the gatekeeper as well as the trusted host. That is extra work for a team, and every new part can also hold new bugs.

  • A single point of failure

    If the gatekeeper stops, nothing can reach the backend. Run redundant copies and scale them automatically, so capacity and availability hold up when one copy fails.

Tip

Keep the gatekeeper thin. Business rules placed inside it tie it to the app, so both must change together. Keep those rules in the trusted host. Microsoft's guidance warns that getting pulled into application processing introduces coupling (a tight link where a change in one part forces changes in another) between services.

When to use it

The pattern fits apps that handle sensitive data, face hostile traffic, or run critical operations that must not expose back ends directly. It also fits when you want validation kept apart from core processing.

  • Good fit

    Use this pattern when you handle sensitive information, or when services need strong protection from malicious traffic.

  • Shared checks

    The pattern helps when request validation must run apart from the main tasks, or when you want to centralize validation to simplify maintenance.

  • Poor fit

    If built-in controls on the back-end service already meet your security and validation needs, a dedicated gatekeeper tier may add cost without much benefit. The same goes when a strict delay limit leaves no room for an extra hop.

Check your understanding

Try these two short scenarios. Each one needs the ideas above to answer well.

Quick check

A startup's public API server both parses user uploads and holds the database password. An attacker exploits a bug in the upload parser and takes over the server. Which redesign would have limited the damage, and what must be true about the backend?

Quick check

A team runs a public high-score list for a game. It holds no private data, and the page must load almost as fast as it does today. Should the team add a gatekeeper tier?

Key takeaways

A gatekeeper is the public guard. It validates and sanitizes requests, does not access the trusted host's credentials or keys, and forwards only clean work. The trusted host is the protected worker that holds the keys and does the processing. Put the two on separate machines, keep the link between them private and encrypted, and make the guard redundant so it does not become a single point of failure.

Sources

How is this lesson?

Last updated on 18 November 2026

Learn with me

Every lesson is free. I add new ones as I learn. Have a question, or want help with your own work? Book a short call.