Gateway Pattern
ELI5 — The Vibe Check
A gateway wraps access to an external system behind a nice, clean interface. Your code talks to the gateway, and the gateway handles the messy HTTP calls, XML parsing, and retry logic. It's the diplomat between your clean code and the ugly outside world.
Real Talk
An object that encapsulates access to an external system or resource, providing a domain-friendly interface. Gateways abstract away protocol details, data format differences, and connection management. Unlike repositories (which abstract data storage), gateways typically wrap external APIs, messaging systems, or third-party services.
When You'll Hear This
"The payment gateway wraps Stripe's API so our domain code never deals with HTTP requests." / "If we switch from Stripe to Braintree, we just write a new gateway — the use cases don't change."
Related Terms
Adapter Pattern
You're in Europe with a US charger. You need an adapter. In code, your app expects a PaymentProcessor with a .pay() method, but the new Stripe SDK uses .
Anti-Corruption Layer
An anti-corruption layer is a translator between two systems that speak different languages.
Ports and Adapters
Ports and Adapters (aka Hexagonal Architecture) means your app defines 'ports' (interfaces) and the outside world connects through 'adapters.
Repository Pattern
Repository Pattern puts a layer between your business logic and your database, so your business code never writes SQL directly.