API / Microservices Design Patterns Interview Questions
What is the Anti-Corruption Layer (ACL) pattern in microservices?
The Anti-Corruption Layer (ACL) is a translation boundary placed at the edge of a service to prevent an external model — typically from a legacy system or a foreign bounded context — from contaminating the service's own domain model. Without it, the consuming service must adopt the vocabulary, data shapes, and assumptions of the external system, gradually corrupting its clean internal design.
The ACL consists of three collaborating components:
- Facade — presents a clean interface to the internal domain, hiding the existence of the external system entirely.
- Adapter — calls the external system's API, reads its events from a message broker, or queries its data store on behalf of the facade.
- Translator/Mapper — converts between the external model and the internal domain model in both directions. For example, a legacy ERP might call a product a "SKU Item" with a flat
unitPriceinteger field; the translator converts this into the internalProductaggregate with a properMoneyvalue object.
Key use cases:
- Integrating with a legacy monolith during a Strangler Fig migration — the new service has its own clean model while the ACL handles translation to/from the old system.
- Consuming a third-party SaaS API without exposing its schema to your core domain model.
- Bridging two bounded contexts that use overlapping but divergent concepts of the same entity.
The ACL ensures that internal domain objects evolve independently of whatever is outside the boundary. When the external system changes its model, only the ACL needs updating — not the core domain logic. This is especially valuable during long-running migrations where the legacy system remains in use for months or years.
Invest now in Acorns!!! 🚀
Join Acorns and get your $5 bonus!
Acorns is a micro-investing app that automatically invests your "spare change" from daily purchases into diversified, expert-built portfolios of ETFs. It is designed for beginners, allowing you to start investing with as little as $5. The service automates saving and investing. Disclosure: I may receive a referral bonus.
Invest now!!! Get Free equity stock (US, UK only)!
Use Robinhood app to invest in stocks. It is safe and secure. Use the Referral link to claim your free stock when you sign up!.
The Robinhood app makes it easy to trade stocks, crypto and more.
Webull! Receive free stock by signing up using the link: Webull signup.
More Related questions...
