Open table of contents
Before rewriting, identify what makes change difficult
Legacy modernization often starts with replacing technologies: COM with REST, an old runtime with a new one, a monolith with microservices or a desktop interface with a web application.
But age is only part of the difficulty. Years of operation accumulate undocumented business rules, exceptions, external dependencies, data quirks and operational workarounds. A rewrite undertaken without understanding them can fail to preserve behavior that the business still needs.
A complete replacement is therefore not always the first step. Keep the existing system’s value while creating a boundary that prevents its dependencies from spreading throughout the new application. That boundary can make subsequent changes smaller.
This Architecture Note first examines semantic, type, execution and data boundaries, then connects them to a case involving a Windows/COM service and a web application. Code values, migration steps and verification criteria are illustrative, not disclosures of a customer implementation or reports of completed tests.
Separate what you can change from what you cannot
Consider an external data service that requires a Windows COM object and a proprietary data container. Its data remains valuable, but clients must understand an operating system, state management and vendor-specific formats. A browser cannot consume that interface directly.
Deciding to “rewrite everything as REST” does not give you control over the vendor’s service. What you can change is the connection between your application and that service.
Define the capabilities the application needs—such as search, detail retrieval and history—as a contract. Place the necessary COM calls and translations in an adapter. The application depends on its own contract, while the boundary implementation takes responsibility for accommodating the external system.
Scroll horizontally to view the complete diagram.
Read the diagram as text
Clients use an application API and domain contract. The anti-corruption layer translates types, state and errors to and from the external system. COM, Windows and vendor records remain inside the integration boundary.
This does not remove the operating-system dependency. Windows and COM remain execution requirements on the adapter side. What changes is where that knowledge is needed and how far a change can propagate.
An anti-corruption layer translates meaning, not just transport
An Anti-Corruption Layer in Domain-Driven Design prevents another system’s model and semantics from dictating your own design. Microsoft describes it as a translation layer between subsystems with different semantics, allowing external dependencies to be used without constraining the application’s architecture. [1]
Putting COM function numbers and modes into HTTP parameters changes the transport. If every consumer still needs the vendor’s state machine and code tables, the semantic dependency remains.
| Upstream representation | Questions at the boundary | Application contract |
|---|---|---|
| Integer status code | Meaning, undefined values and permitted combinations | Business states and treatment of uninterpretable responses |
| Date-like string | Format, calendar, time zone and business-date definition | Distinct date or instant types |
| Number with a separate unit | Currency, scale, precision and rounding | Values with explicit units and precision |
| Null or sentinel value | Unavailable, inapplicable, missing or failed? | Explicit states where the distinction matters |
| Vendor exception | Cause, execution outcome and retry safety | Errors the consumer can act on |
Translating an external representation is different from deciding new business policy. If discounting and approval rules collect in the translation layer, it becomes another large business system. Keep compatibility and translation at the boundary; keep business decisions in the appropriate domain or application layer.
Types make translation assumptions explicit
F# discriminated unions represent alternatives and the data associated with each one. [2] With Option and Result, missing values and failed conversions can be distinguished from normal success.
The following assumes the meanings of the codes have been established from a specification. It is an illustrative example, not an actual vendor code table.
type AccountStatus =
| Pending
| Active
| Suspended
type StatusDecodeError =
| MissingStatus
| UnrecognizedStatus of int
let decodeStatus (raw: int option) : Result<AccountStatus, StatusDecodeError> =
match raw with
| None -> Error MissingStatus
| Some 0 -> Ok Pending
| Some 1 -> Ok Active
| Some 7 -> Ok Suspended
| Some code -> Error (UnrecognizedStatus code)
Do not silently turn an unknown value into Active or Pending. This example also rejects 99. If a vendor formally defines that value, establish its meaning and choose a deliberate representation. Guessing should not produce an apparently valid business state.
A raw code may be retained in an internal conversion error without being serialized into the public JSON contract. Consumers can receive a stable “uninterpretable upstream response” outcome while restricted diagnostics retain the investigation detail.
Types do not make a wrong mapping or time-zone interpretation correct. Nor does serializing an F# type directly guarantee a stable web API. Specify external shapes, required fields, enumerations and unknown-value behavior separately, and assess consumer compatibility when changing them.
Start with the capabilities consumers actually need
An external API may expose 500 operations while the new application needs only search, details and history. Starting with those capabilities limits exposure, mapping logic, maintenance and verification scope.
Assess the boundary against these properties.
| Property | Question |
|---|---|
| Stable | Can small upstream changes be absorbed without forcing consumer changes? |
| Explicit | Are meanings, missing values, errors and effects clear? |
| Observable | Can latency and failure be located in calls and translation? |
| Testable | Can translation be checked separately and assumptions compared with the provider? |
| Replaceable | Can some internal implementations change without changing consumers? |
| Narrow | Does it expose needed capabilities rather than a generic vendor-API relay? |
Stability does not mean freezing a contract forever. It means managing compatibility and communicating changes. Where two APIs already share the same semantics, a substantial translation layer may offer little value. [1]
A boundary does not have to be a separate service
Different dependencies call for different boundaries.
| Boundary | Dependency isolated | Example decision |
|---|---|---|
| Protocol | COM, SOAP or RPC invocation | Introduce an HTTP API for browser or cross-language access |
| Data | Strings, vendor records and database structures | Translate into values the domain needs |
| Domain | States, units and business meanings | Keep vendor code tables out of consumers |
| Process and execution | Threads, sessions, hangs and crashes | Isolate execution workers from admission |
| Deployment and operations | OS, SDK, update cadence and credentials | Deploy Windows integration and web components independently |
A logical boundary can be a module in the same process. A separate service adds networking, authentication, timeouts, partial failures and deployment work. Choose a physical boundary when independent scaling or fault containment justifies it.
Type translation does not remove COM execution constraints
With COM, establish the object’s STA/MTA apartment model and calling-thread requirements. Cross-apartment calls involve marshaling; an object cannot simply be assumed safe to move between arbitrary threads. [3]
SDK bitness, sessions, object lifetime, concurrent-call support and licensed connection limits also matter. Do not assume each HTTP request can invoke the object from any available thread. A dedicated worker and a bounded queue may be appropriate.
An HTTP timeout does not necessarily cancel the COM operation. If work cannot be canceled, design isolation, admission shutdown, cleanup and worker restart accordingly. These are general design concerns, not claims about a particular execution model used in the case described below.
Distinguish incremental replacement from permanent isolation
Once a boundary exists, implementations can change behind it. But creating a boundary and deciding to retire the old system are separate decisions.
Strangler Fig replaces functionality incrementally around an existing system. Fowler describes gradual, visible investment and returns while the business continues operating. [4] It depends on being able to redirect interactions at a perimeter or separate the functionality being replaced.
For a deeply embedded library or component, Branch by Abstraction can be more suitable. Move callers to a common abstraction, allow old and new implementations to coexist beneath it, and switch implementations gradually. [5] This requires access to change those internal callers.
Scroll horizontally to view the complete diagram.
Read the diagram as text
Strangler Fig progressively routes requests at a system perimeter. Branch by Abstraction redirects internal callers to a common abstraction and changes its implementation. Neither automatically resolves data ownership or consistency, and neither requires microservices.
Neither technique makes microservices the goal. Incremental change may be possible within one process. Request routing also does not solve data migration or transaction consistency automatically.
When an external vendor service will remain, maintaining an anti-corruption layer indefinitely can be reasonable. Distinguish migration toward retirement from isolation of a dependency you intend to retain. Define either an exit condition or a continuing operating contract for the boundary.
Preserve execution outcomes when translating errors
HRESULT values and vendor exceptions do not need to appear directly in a user interface. But translating every failure into “temporarily unavailable” prevents consumers from making safe decisions.
| Distinction at the boundary | Consumer response |
|---|---|
| Input violates the contract | Request correction rather than repeating the same input |
| Permission denied | Reject without unnecessarily exposing resource existence |
| Resource absent | Apply the agreed absence semantics |
| Upstream unreachable | Wait or retry according to operation semantics and limits |
| Upstream response cannot be interpreted | Avoid fabricated success; record and investigate |
| Update outcome unknown | Reconcile by operation identity and avoid duplicate effects |
A timeout after an update request is not evidence that the update did not happen. The upstream system may have committed it and lost the response. HTTP semantics likewise caution against automatically retrying non-idempotent requests without a basis for safety. [6]
Retry safety depends on operation semantics, deduplication, result lookup and upstream guarantees. A locally recorded operation ID alone does not make an external update execute exactly once. If reconciliation is impossible, preserve an unknown outcome and allow a manual resolution path.
Connect internal diagnostics to the outward result using a correlation ID. Routine logs do not need raw requests, credentials or entire proprietary containers.
Decide data ownership and rollback limits first
Even a read-only integration needs contracts for source permissions, usage terms, freshness and cache lifetime. A migration involving writes also needs an explicit answer to which system accepts updates to which data.
For example, the old system might own customer records while the new system owns settings for a new feature. If both databases can freely update the same data without field or aggregate ownership, the design must resolve conflicts, reordered changes, duplicates and partial failure.
Scroll horizontally to view the complete diagram.
Read the diagram as text
The old system initially owns writes. Stop old-side writes and reconcile in-flight work and remaining changes before transferring write authority. Once the new side accepts writes, rollback must account for those changes; reversing a route is insufficient.
Cutover requires a way to stop new old-side writes and establish what happened to in-flight operations. Reconcile remaining changes and business-level consistency before transferring write authority. Include direct database access and other paths that bypass the API.
If temporary dual writes are unavoidable, writing to both sides is only the start. Specify ordering, failure recording, redelivery, reconciliation and conflict resolution as separate design obligations.
After the new implementation has accepted writes, reversing a routing flag is insufficient for rollback. Establish whether the old implementation can represent and receive those changes. Separate the conditions for going back from those that require a forward repair.
Operate the boundary as a production system
Adapters add latency, resource consumption and failure points alongside their translation logic. Microsoft calls out operation, monitoring, consistency and resilience around a possible single point of failure. [1]
Set deadlines, retry budgets and delays, queue limits and concurrency bounds. Consider circuit breakers for sustained failures and bulkheads for resource isolation. More workers or replicas cannot override upstream session limits or capacity.
Browser access creates an exposure surface that a local call did not have. Add user authentication and authorization, tenant separation and request limits. A powerful adapter credential must not allow a user to retrieve data outside their own authority.
Distinguish a live process from a functioning business path through the upstream service. Health probes themselves may consume provider capacity or licensed usage.
Observe calls and translation separately
Break total duration into admission wait, upstream calls, transformation and response handling. Track successes and failures alongside timeouts, unknown outcomes, unrecognized values, conversion failures, retries and queue depth.
Use correlation IDs to connect API, adapter and upstream records where possible. Even when the provider cannot accept trace context, the adapter can observe its own outbound call. Record adapter, SDK, mapping and API-contract revisions to diagnose behavior changes after an update.
Do not put unbounded request IDs into metric labels. Use logs and traces for individual investigations, while avoiding sensitive content and uncontrolled telemetry cost.
Fixtures alone cannot detect provider changes
Checking that response X becomes domain result Y is necessary. Cover unknown values, absence, overflow, dates, encoding and malformed records. But saved response fixtures will not tell you that a vendor’s live behavior has changed.
Fowler’s description of Contract Test addresses this distinction: verify separately that a test double still represents the external service’s contract. [7]
Scroll horizontally to view the complete diagram.
Read the diagram as text
Fixtures exercise translation and errors. A separate path uses the real vendor API or SDK in an approved verification environment to check the assumed upstream contract. Consumer compatibility at the application API is another release condition.
| Verification layer | What it can establish | What it cannot establish alone |
|---|---|---|
| Mapping fixtures | Types, semantics and errors for assumed inputs | Current provider behavior |
| Actual provider or SDK contract | Shapes, required fields, known semantics and version differences | Every business case and failure condition |
| Application API consumers | Outward representations and relied-upon behavior | Upstream performance and operation |
| Business scenarios | Whether a sequence produces required outcomes | Unexercised load, concurrency and fault conditions |
Use approved environments and operations for provider checks. Sending duplicate production writes is not a shortcut to comparison. Even confirmed side-effect-free reads must respect quotas, cost and data-use restrictions.
When comparing against the old implementation, do not assume all old behavior is correct. Separate required business semantics, quirks temporarily retained for compatibility, and defects to fix. Agree expected behavior with business owners. These are proposed verification methods, not claims of measured coverage or passing results.
The CoRISE case: turning prior technology into a customer web application
In “Modernizing Legacy APIs into a Web Application Platform”, a Windows/COM service with proprietary data formats was connected to a browser-based React application.
The underlying F# adapter and REST technology had been independently developed earlier by CoRISE’s technical advisor. CoRISE used those assets and expertise for customer requirements, web application design and development, API integration and the user experience.
Scroll horizontally to view the complete diagram.
Read the diagram as text
An external COM/data service is exposed through the technical advisor’s pre-existing F# adapter, domain model and REST technology. CoRISE used those assets for customer requirements, React application design/development and API integration. Future clients are extension possibilities, not delivered outcomes.
The adapter isolates COM calls and vendor representations behind typed domain models and REST. The React application delivered by CoRISE can consume an ordinary web API.
The architectural value is not the name React or HTTP. It is the boundary that keeps COM and proprietary-container knowledge out of the application and its screens. Windows remains a dependency, but its direct influence is confined to a smaller layer.
This also creates extension possibilities for other web clients or batch consumers; it does not mean all those clients were delivered. The illustrative status codes, worker isolation, write cutover and contract checks in this article are not presented as implemented features of that engagement. The case page describes the delivered scope and attribution.
Define when to retain and when to replace
Long-term coexistence can be reasonable when a service retains business value, has continuing support and meets operational needs behind the boundary. Localizing technical debt is valuable even when it cannot be eliminated.
A boundary may be insufficient when support ends, unacceptable security risk remains, the data model no longer works, or the business has fundamentally changed. Complete replacement can then be the lower-cost or lower-risk option.
| Decision | Example conditions |
|---|---|
| Retain behind a boundary | The external system cannot be changed, retains value and support, and can meet operating requirements |
| Replace by capability | Functionality and migration paths can be separated, allowing incremental value |
| Replace completely | Continued use is too risky, or replacement has a small, well-understood scope |
| Reduce or retire use | Business value no longer justifies maintenance |
Retaining a dependency should include review triggers: support deadlines, operating cost, incident rates, time needed to change behavior and evolving business requirements.
The first design may be a boundary rather than a new system
Identify the existing system’s value, then the dependencies that obstruct change. Choose a useful seam, isolate the needed capabilities, make them observable and verifiable, and change the areas with the greatest business value.
CoRISE’s focus is not just the percentage of old technology replaced. It is whether the business can continue operating while change is contained and the customer-facing application can improve independently.
Modernization can mean preventing legacy dependencies from spreading throughout the new system. Preserve value, localize constraints and make the next change easier. Architecture can change without rewriting everything.
References
The Microsoft anti-corruption-layer reference is pinned to an April 2026 repository snapshot. Code and migration examples are explanatory designs informed by these sources and the case’s attribution, not a complete implementation guide for a particular product.
- Microsoft Azure Architecture Center — Anti-Corruption Layer pattern, revision
f850a504, April 30, 2026 (UTC). Semantic translation, placement, operations and consistency. - Microsoft — F# Discriminated Unions. Representing alternatives and associated data. The consulted page’s update metadata is October 3, 2025.
- Microsoft — Processes, Threads, and Apartments. COM execution and cross-apartment calls. Repository snapshot dated April 22, 2026.
- Martin Fowler — Strangler Fig, August 22, 2024. Incremental legacy replacement and delivery of value.
- Martin Fowler — Branch By Abstraction, January 7, 2014. Coexisting implementations behind an abstraction.
- RFC 9110 — HTTP Semantics, §9.2.2 Idempotent Methods, June 2022. Conditions for automatic retries of non-idempotent requests.
- Martin Fowler — Contract Test, January 12, 2011; revised January 1, 2018. Checking agreement between an external service and a test double.