In microservice architecture, an adapter is a boundary component that converts between a service’s internal model or interface and an external protocol, technology, or representation—most commonly in the Ports and Adapters (hexagonal) style, where adapters implement ports so the domain core stays insulated from databases, message brokers, HTTP, and third-party APIs. The role is therefore primarily translation and boundary isolation, not business decision-making: adapters move data and effects across a seam, while the core decides what those data and effects mean.
The important ambiguity is that “adapter” names two related but distinct things in microservice practice. One is the architectural pattern (hexagonal/clean architecture adapters around a service’s domain). The other is the integration pattern (adapters that reconcile incompatible interfaces between services, sometimes called integration adapters, anti-corruption layers, or message translators). Both share the same job—protecting one side from the other’s assumptions—but they sit at different scopes. A single service can contain many internal adapters and also expose or consume an integration adapter. Neither use requires a specific framework, language, or deployment topology.
What an adapter actually does
An adapter’s work can be separated into four concrete responsibilities:
1: Protocol translation. Converting an inbound HTTP request, gRPC call, AMQP message, scheduled job trigger, or CLI invocation into a call on an application port. Outbound, converting a port invocation into SQL, an HTTP client call, a publish to a broker, or a file write. 2: Model translation. Mapping wire formats, database rows, and vendor payloads into domain types and back. This includes handling nullability, optional fields, enums, units, currency, timestamps and time zones, identifiers, and versioning differences. 3: Technical failure translation. Turning timeouts, connection resets, HTTP status codes, broker nacks, and driver exceptions into the application’s error vocabulary—and deciding retryability at the boundary rather than leaking vendor-specific exceptions into the core. 4: Cross-cutting boundary concerns. Authentication and authorization enforcement at the edge, request validation against a schema, idempotency-key handling, rate limiting, observability (traces, metrics, structured logs), and transaction demarcation for the specific technology.
What an adapter should not do is own business invariants. If an adapter decides that an order is valid because its total exceeds a threshold, that rule now lives in two places once another entry point appears. The classic symptom of adapter leakage is duplicated validation across an HTTP handler and a message consumer—both “adapters” reimplementing the same rule because the core does not enforce it.
Ports and adapters inside one microservice
In the hexagonal formulation, the application core exposes ports: interfaces expressed in the core’s own terms. A driving (primary, inbound) port is what the outside calls, such as PlaceOrder. A driven (secondary, outbound) port is what the core needs, such as OrderRepository or PaymentGateway. Adapters implement or invoke these ports:
A driving adapter is the REST controller, gRPC handler, message listener, or CLI that receives an external stimulus and calls the inbound port. A driven adapter is the Postgres repository, the Kafka producer, the Stripe client, or the SMTP sender that fulfills an outbound port.
The payoff is dependency direction: the core depends on abstractions it defines, and infrastructure depends on the core, not the reverse. That makes the core testable without a database or broker and allows swapping technology—say, replacing a relational repository with an event-sourced one—without rewriting business logic.
A concrete example clarifies the seam. A PaymentGateway port might declare authorize(amount: Money, method: PaymentMethod): AuthorizationResult, where Money and PaymentMethod are domain types and AuthorizationResult is a small domain-level sum type (approved with reference, declined with reason, or indeterminate). The Stripe adapter maps this to Stripe’s API objects, converts minor units and currency codes, maps Stripe decline codes into the domain’s reason vocabulary, and translates transport failures into Indeterminate rather than throwing a vendor exception. A fake adapter in tests returns scripted results. The core never imports the vendor SDK.
Notice the deliberate distinction between approved, declined, and indeterminate. That third state is a domain concept created by thinking about distributed reality; the adapter is where the messy evidence (timeout after the request was sent) gets classified. If the adapter instead mapped every non-2xx response to a generic failure, the core could not distinguish “definitely not charged” from “unknown,” and retry logic would become unsafe.
Adapters between services: the anti-corruption layer
When one microservice consumes another’s API or events, an integration adapter (often an anti-corruption layer, or ACL) prevents the upstream service’s model from colonizing the downstream domain. Suppose a billing service consumes customer data from an identity service whose payload uses account_status with values ACTIVE, SUSPENDED, CLOSED, plus a nested profile object. The billing domain may only care about “billable” versus “not billable.” The ACL maps the upstream vocabulary into billing’s own terms, absorbs upstream versioning, and centralizes the decision about what an unknown future status means—typically a conservative default with alerting, not a silent pass-through.
This is also where message translators live in event-driven systems: converting an upstream event schema into a local event or command, deduplicating by message ID, and handling out-of-order delivery according to the consumer’s needs. The adapter is the natural home for schema-evolution shims, because it is the only place that knows both schemas.
Two cautions matter here. First, an ACL is not a substitute for upstream API versioning discipline; it buys the downstream team time and independence, but it accumulates mapping code that must be maintained. Second, “adapter” in this sense overlaps with the API gateway and BFF (backend-for-frontend) patterns, which are also boundary translators, but at a coarser scope: a gateway typically handles cross-cutting edge concerns for many services, while a per-service adapter handles one service’s contract. Calling all of them “adapters” is common and not wrong, but the responsibilities and failure modes differ.
Adapters versus related patterns
The term is often confused with neighboring patterns, and the distinctions are practical:
| Concern | Adapter (hexagonal) | Repository | Facade | Gateway / BFF | Sidecar proxy |
|---|---|---|---|---|---|
| Primary job | Translate protocol/model at a boundary | Abstract persistence behind a collection-like interface | Simplify a complex subsystem behind one interface | Route and shape traffic for clients | Handle network concerns (mTLS, retries) out of process |
| Owns business rules? | No | No (usually) | No | Sometimes (aggregation, shaping) | No |
| Typical location | Inside a service, at its edge | Inside a service, driven side | Inside or in front of a subsystem | At the system edge | Alongside the service |
| Failure it prevents | Core coupled to infrastructure | Core coupled to a database | Callers coupled to internals | Clients coupled to many services | App coupled to network policy |
The repository is arguably a specialized driven adapter; the distinction is mostly about interface style (collection-like access versus explicit operations). A facade is about simplifying an interface, not translating between incompatible ones, though it can contain adapters. A sidecar proxy handles transport-level concerns without changing the application’s model; it does not translate domain payloads.
A useful counterexample: putting retry logic in an HTTP adapter for a payment authorization is dangerous if the operation is not idempotent. The adapter’s job includes knowing which failures are safe to retry and whether it can supply an idempotency key; a naive “retry on 5xx” inside the adapter can double-charge. This is a case where the boundary component must understand the semantics of the port it implements, not just the wire protocol.
Why the pattern matters in microservices specifically
Microservices multiply boundaries: network calls, independent deployments, heterogeneous storage, and teams with different vocabularies. Adapters are the mechanism that keeps those boundaries from turning into coupling. Three benefits follow directly:
Independent evolvability. A service can change its database or upgrade a vendor SDK without touching the domain, because the adapter absorbs the change. Conversely, the domain model can be refactored without rewriting transport code. Testability. The core can be tested against in-memory fakes of its ports. Contract tests then verify that real adapters honor the port’s expectations—especially error behavior, which is where most integration bugs live. Contained blast radius of technology choices. Framework annotations, ORM entities, and vendor types stay in the adapter layer. This reduces the chance that a framework upgrade ripples through business logic.
There is a cost, and it is real. Adapters add indirection: more interfaces, more mapping code, more files. For a small CRUD service whose “domain” is a table, a full hexagonal apparatus is ceremony. The pattern earns its keep when the domain has meaningful rules, when multiple entry points exist (HTTP plus events, say), when the persistence or vendor technology is likely to change, or when the service must defend against an upstream model it does not control. A useful heuristic: if you cannot articulate a rule that belongs in the core but not in the adapter, the boundary may not be worth drawing yet.
Common failure modes
Leaky adapters. Domain entities annotated with ORM or serialization metadata, vendor exceptions surfacing in the core, or HTTP status codes used as business logic. Each couples the core to a technology.
Anemic ports. A port that mirrors a specific database or vendor API (findByXAndYOrderByIdDesc) rather than expressing a domain need. The adapter then has nothing to translate, and the core is coupled through the interface instead of through imports.
Business logic in the adapter. Discount calculations, eligibility checks, or state transitions implemented in controllers. These must move to the core so every entry point shares them.
Over-abstracting. Creating a port for every class “just in case,” producing interfaces with one implementation and no test value. Ports should exist where substitution or isolation is genuinely useful.
Ignoring the indeterminate case. As in the payment example, adapters that collapse “unknown outcome” into success or failure create unsafe retries and reconciliation gaps.
Mapping drift. Multiple adapters mapping the same external payload differently. Centralizing the mapping in one adapter (or a shared mapping module owned by that adapter) prevents divergence.
Practical guidance, briefly
Define ports in the core’s vocabulary and keep them small. Put all framework and vendor types behind driven adapters; keep inbound adapters thin, delegating to application services. Write contract tests for each real adapter against its port, covering success, failure, timeout, and malformed input. Handle idempotency, retries, and deduplication explicitly at the boundary, and document which operations are safe to retry. Treat schema translation for upstream services as a maintained artifact with tests, not an afterthought. Finally, name the seam honestly in code and docs: distinguishing a driving adapter, a driven adapter, and a cross-service anti-corruption layer helps reviewers see where business rules are allowed to live.
In short, adapters in microservice architecture are the translation layer that lets a service’s core remain expressed in its own terms while the outside world changes protocols, schemas, and vendors around it. Their value is isolation and evolvability; their risk is becoming either a leaky pipe that couples the core to infrastructure or a second home for business rules. The pattern is a tool for managing boundaries, and like any boundary, it should be drawn where the cost of coupling is higher than the cost of the seam.