Blog
Posts and series that take software and IT from the basics to advanced topics: from programming languages and databases to architecture and AI.
No Transactions Across Microservices: Embracing Eventual Consistency by Design
Distributed transactions (2PC) are not used across services; a rule that needs immediate consistency stays in one service, and a flow spanning several services is built with sagas and compensating actions, with events going through an outbox. The real error TransactionScope gives on Linux and macOS, a choreographed checkout saga, intermediate states in the domain, and eventual consistency shown to the user with 202 Accepted.
Data Ownership and Database per Service: Why Avoid a Shared Database?
A shared database creates coupling that appears in no contract; each service's data should be private to it, and others should reach it through API composition, a local copy replicated through events, or a CQRS read model. Enforcing the boundary with schema-level permissions in SQL Server, a version-checked copy driven by BookRenamed, the snapshot difference, reference data and CDC for reporting.
Drawing Service Boundaries: Business Capabilities, Bounded Contexts and Types of Coupling
A service boundary is drawn not around tables or entities but around business rules that change together: a service holds at most one bounded context and is owned by a single team. The business capability and subdomain approaches, Microsoft's boundary guide, Newman's domain, pass-through, common and content coupling, the entity service anti-pattern, and Customer as three separate models in three contexts.
The Cost of Microservices: When Are They Unnecessary and When Are They Inevitable?
Microservices are unnecessary for a single-team system without the prerequisites (automated provisioning, monitoring, fast deployment); they become inevitable once teams waiting on each other and parts that scale differently become measurable. The real cost of a network call, measured, plus the fallacies of distributed computing, Fowler's prerequisites, a correct reading of the Prime Video case and a decision checklist for Bookstore.
What Are Microservices and What Are They Not? Independent Deployability and Information Hiding
A microservice is a service modeled around a business domain that can be deployed without touching the others; the criterion is not size but independent deployability and information hiding. Lewis and Fowler's nine characteristics, Newman's definition, separating the contract from the internal model in C#, the difference from SOA, and Bookstore's service candidates.
Extracting a Module into a Service: When, In What Order and With Reversible Steps
The reason to extract a module into a service must be measurable pressure (independent scaling, a separate team, compliance, different availability), not "it's extractable"; the extraction goes through data isolation, an HTTP implementation, a broker and separate deployment, with every step reversible. We move Bookstore's Payments module into its own process without touching Ordering and show one setting bringing it back into the monolith.
Protecting Module Boundaries: Architecture Tests, Build Rules and Module-Level Testing
Module boundaries are protected at four levels: the compiler (internal), the build (an MSBuild check in Directory.Build.targets that stops Core-to-Core references), tests (ArchUnitNET rules parameterised over the modules) and review (CODEOWNERS). With real output we show the rules catching a forgotten public type on their first run, a mutable DTO added to Contracts and a Core dependency inside a method body.
Data Isolation per Module: Schema per Module with EF Core and Cross-Module Queries
Each module puts its tables into its own schema with HasDefaultSchema in its own DbContext, keeps its migration history in its own schema with MigrationsHistoryTable, and runs in the database as a user authorised only on its own schema. On SQL Server we show Ordering's user being refused a join to a Catalog table with error 229, and produce the same report without breaching isolation through contract calls, an event-fed read model and reporting views published by the modules.
Asynchronous Communication Between Modules: Integration Events, In-Memory Bus and the Outbox
Modules notify each other with integration events from Contracts; a forty-line library-free in-process bus is enough for that, but publishing the event only in memory loses it when a handler fails or the process crashes. With real SQL Server output we show in-memory publishing losing a Bookstore shipment, and a minimal outbox in the order's transaction plus a per-module inbox reserving stock only once when the same event arrives three times.
Synchronous Communication Between Modules: Public Contracts, In-Process APIs and Preventing Entity Leaks
Modules should call each other through an interface in the Contracts project, with methods that return records and are shaped by the consumer's scenario; injecting another module's DbContext turns that module's internal model into a public contract. We measure per-line versus per-cart calls for a 20-book cart, and show the runtime circular dependency the Contracts split misses and how a refactoring in Catalog breaks Ordering.
Modular Monolith Solution Structure in .NET: Module Projects, internal and Module Registration
Each module gets two projects: a small Contracts project other modules can see and a Core project where everything is internal; the Host is just the composition root calling AddXModule() and MapXEndpoints(). We go from an empty solution to a running three-module Host, show with real CS0234/CS0122 errors where project references and internal protect the boundary and where they don't, and list concretely what may and may not go into the Shared Kernel.
Finding Module Boundaries: Business Capabilities, Bounded Contexts and Data Ownership
Module boundaries are drawn by business capability and data ownership, not by technical layer: each bounded context becomes a module and each table gets exactly one writer. Using an EF Core interceptor in Bookstore we measure three modules writing to the Books table and two to Orders, show why the Book inside an Order must be a separate snapshot model, and list the symptoms of a wrong boundary.