Skip to content

Serverless Vendor Lock-In: Ports, Adapters, and Switching Costs

Serverless platforms remove a lot of operational pain, but they do not remove the need to think about how tightly your business logic is tied to a specific managed service. This guide explains why the useful question is not whether lock-in exists, but how much a future switch would cost. It then shows how a ports-and-adapters structure keeps that cost low by isolating database and notification dependencies behind small interfaces that can be tested and replaced independently.

What vendor lock-in actually means

The common definition is economic: a customer becomes dependent on a vendor for products and services and cannot move to another vendor without substantial switching costs. That definition is accurate but not very actionable. A more useful framing for engineering teams is that lock-in is the size of the bill you would pay to leave.

That bill has several parts. There is the direct cost of rewriting integrations, the cost of retesting behavior that used to be covered by existing tests, and the cost of running two systems in parallel while you migrate. There is also the cost of decisions made earlier: skipped automated tests and shortcuts in application architecture tend to make a migration more expensive than keeping the current setup.

A simple scenario makes the point. Suppose a team rents compute from a large provider and gradually adopts that provider's managed database, storage, and messaging services. The services are cheap and convenient, and the team embeds them directly into the business logic. If prices rise or the service changes, moving to another provider means adjusting the application, not just changing an endpoint. The application has become coupled to the provider's way of doing things.

That does not mean every managed service is a mistake. It means the coupling should be a deliberate choice with a known exit cost, not an accident of convenience.

Decide how low switching costs need to be

Before choosing an architecture, estimate two things: how likely a switch is, and how much it would cost. The answer sets the budget for abstraction.

A useful checklist:

  • Likelihood: Is the provider's pricing history stable, or has it changed direction before? Treat any specific pricing history as a dated claim to verify against current provider documentation, not as a guarantee.
  • Blast radius: If the service disappeared tomorrow, which parts of the product would stop working?
  • Migration effort: How many services touch the dependency, and how much of that behavior is covered by automated tests?
  • Parallel-run cost: Can old and new implementations coexist during a transition, or would a cutover be all at once?
  • Business impact: Would a few weeks of migration work be tolerable, or would it threaten a launch or a contract?

When the risk is low and the cost of a switch is small relative to the business, heavy abstraction may not be worth it. When the dependency is deeply embedded and the exit cost is high, the architecture should make the dependency replaceable. The goal is not zero lock-in; it is a switching cost you have chosen and can afford.

Why a serverless app still needs tests

Managed infrastructure does not test your business logic. A bug in a serverless function will not crash the platform, but it can scale automatically and reach more users before anyone notices. Serverless applications are also rarely isolated monoliths: they usually contain several services that interact with each other and with external dependencies.

A typical flow illustrates the risk. An external platform sends a webhook event to an API gateway. The gateway routes the event to a function that handles a specific scenario, such as a slash command or a button action. That function processes the event, publishes it to a notification topic, and replies to the external platform. A separate business-logic service consumes the message and acts on it. If any one of those pieces fails or changes shape, the business logic may not run correctly.

Tests cannot stop an external dependency from changing. They can, however, confirm that a change in your own code was intentional and that the pieces still fit together. That is why integration tests matter more, not less, when an application is split into many small services.

Four risks to cover in a serverless architecture

A useful way to organize test coverage is to separate the risks an application faces:

  • Configuration risks: Is the database table configured correctly, and does the function have the access rights it needs?
  • Technical workflow risks: Is the incoming request parsed and used correctly?
  • Business logic risks: Does the application logic behave the way it should?
  • Integration risks: Is data stored in the database correctly, and are outbound calls shaped as the external service expects?

End-to-end tests can cover most of these, but relying on them alone is like assembling an entire car just to check whether the windshield wipers work. A layered approach lets you test each risk at the level where it is cheapest to observe.

Ports and adapters in practice

Hexagonal architecture, also called ports and adapters, separates the application core from the outside world. The core defines what it needs; adapters provide it. The pattern suits serverless because it is usually impossible to reproduce the entire production runtime locally during development.

Consider a service that receives a notification, parses it, saves data, and sends another notification. The core of that service exposes three ports:

  • A port for an incoming event.
  • A port for saving data to the database.
  • A port for sending a notification.

Each port has more than one adapter. In production, the notification port might be fulfilled by an adapter that publishes to a managed messaging topic. In tests, the same port can be fulfilled by a local adapter that records the message without calling the cloud service.

The wiring lives in one place, typically a handler file, while the business logic lives in another file that receives its dependencies as parameters. The handler creates the production adapter and passes it in. Tests pass a mock or a local adapter instead. Because the business logic only depends on the port, it does not know or care which adapter is in use.

A worked example: the notification port

The notification port is small by design. The business logic sends a message by calling a method on the notification object it received. Anything that implements that method is a compatible adapter.

In production, the handler constructs an adapter backed by the managed messaging service and passes it to the business-logic function along with the parsed event. In unit tests, the same function receives a mock, and the test asserts that the mock was called with the expected message. In integration tests, the function receives a local adapter, which can be a thin wrapper around native events.

The production adapter is tested separately, against the real messaging service, to confirm that the integration works as intended. This split avoids repeating the same cloud integration check in every business-logic test. It also means a change to the messaging client affects one adapter and its tests, not every service that sends a notification.

Swapping a database without rewriting the app

The same structure applies to databases. If the application talks to a repository rather than a specific database client, the repository becomes the adapter and the operations it exposes become the port.

A migration can then proceed in stages. Create a new adapter for the target database with the same interface as the existing one. Connect services to both repositories at the same time. Move integrations over one by one. When the last service has moved, remove the old adapter.

This is what makes a database choice less frightening: the decision still matters, but it is no longer welded into the business logic. The migration becomes a sequence of adapter swaps rather than a rewrite of every service that touches data. The pattern is illustrated here as a neutral design approach; it is not a report of any particular team's migration outcome.

What tests cannot prevent

Some changes cannot be caught by tests written in advance. An external platform may change its API without notice, or alter behavior in a way that is not documented. A layout change on a mobile client, for example, might break a calendar view while the underlying application still works correctly. Other changes produce a wave of errors.

The response is monitoring, not more unit tests. Watch both the front end and the back end, and react quickly when a third-party change breaks part of the product. On AWS, built-in tools such as Amazon CloudWatch and AWS X-Ray provide visibility, and third-party monitoring services are also available. The architecture keeps the blast radius small; monitoring tells you when something outside your control has changed.

Frequently asked questions

Is vendor lock-in the same as switching cost?

Lock-in describes the dependency; switching cost describes what it would take to leave. Treating the two as the same thing is useful because it turns a vague fear into an estimate you can plan around: how likely is a switch, and how much work would it require?

How does hexagonal architecture reduce lock-in?

It keeps business logic dependent on small ports rather than on a specific vendor's client library. Production adapters connect those ports to managed services, while test adapters provide local substitutes. Replacing a service then means writing a new adapter, not rewriting the core logic.

Should every service be tested against the real cloud service?

No. Testing every business-logic function against the real messaging or database service repeats the same integration check many times. Test the adapter against the real service once, and test the business logic against a mock or local adapter.

Can automated tests prevent third-party API changes from breaking the app?

Not entirely. Tests confirm that your own changes are intentional and that the pieces still fit together. Undocumented changes in an external platform can still break behavior. Monitoring and fast reaction cover that gap.