S

super-dev — full-stack

@super-dev.app · Full-stack · ★ open to work
12.8k subscribers·47 videos·Active since 2017

Full-stack .NET / Angular dev with a DevOps streak on Azure Cloud. Also fluent in Flutter + Firebase. I build products, ship them, and keep them healthy.

Back to articles
{ }
.NET
.NET

Strangle a .NET 8 monolith without breaking everything

Article 1 of 5 — Modern .NET
Minimal APIs, CQRS, gRPC, source generators: clean, testable .NET 8 without the ceremony.

You rarely inherit a greenfield . More often it's a .NET monolith that has been running in production for eight years, that nobody dares touch. The Strangler Fig pattern lets you replace it piece by piece , with no big-bang and no downtime window.

The principle

You put a façade in front of the monolith, then reroute one route at a time toward a new service. As long as a feature hasn't been rewritten, it keeps going through the old code. The day the last route flips over, the monolith is dead — strangled.

An anti-corruption layer

The new code must never speak the legacy's language. You interpose an anti-corruption layer that translates the old world's models into the new one:

C#
1public sealed class LegacyOrderTranslator
2{
3 public Order ToDomain(LegacyOrderDto dto) => new(
4 Id: new OrderId(dto.ORDER_ID),
5 Total: Money.FromCents(dto.TOTAL_CENTS),
6 PlacedAt: DateTime.SpecifyKind(dto.DT, DateTimeKind.Utc));
7}

Route at the right level

The switch is ideally done at the reverse proxy level (YARP, Nginx) rather than in the code, to keep both worlds perfectly isolated. With YARP , a single route in configuration is enough to divert a path to the new service.

  • a migrated route → new service
  • a non-migrated route → monolith
  • a canary → 5% of traffic, then 100%

Measure before you cut

Every migrated route is paired with shadow traffic compared against the old response before cutting for good. You only delete the old code once it is provably dead : as long as a call still flows through it, it stays. Telemetry becomes the migration's referee.

Strangling isn't about rewriting faster. It's about rewriting in a reversible way: at every step, you can roll back with a single line of configuration.
super-dev — portfolio.app
// More in .NET
ƒ()
Minimal APIs + EF Core: a clean .NET 8 API
8 min • 3.1k reads
CQRS and vertical slices without the ceremony
7 min • 2.3k reads
.NET microservices with gRPC
9 min • 1.8k reads