Mert Özen Go Beyond the Code

Blog

Posts and series that take software and IT from the basics to advanced topics: from programming languages and databases to architecture and AI.

Series
1990 posts found
Worker Service and an In-Process Job Queue: Channel, PeriodicTimer and Windows Service/systemd
Backend PART 03

Worker Service and an In-Process Job Queue: Channel, PeriodicTimer and Windows Service/systemd

An in-process job queue built on a bounded Channel returns false from TryWrite when it is full; the endpoint turns that into a 503 with a Retry-After header and applies backpressure. For periodic work, PeriodicTimer doesn't pile up missed ticks: after a long run it fires at most once right away. AddWindowsService and AddSystemd only activate in their own environment, and the queue empties on restart.

8 Nov 2026 10 min 75
IHostedService and BackgroundService in .NET: Lifecycle, Graceful Shutdown and the .NET 10 Behavior Change
Backend PART 02

IHostedService and BackgroundService in .NET: Lifecycle, Graceful Shutdown and the .NET 10 Behavior Change

In .NET 10 the whole of BackgroundService.ExecuteAsync runs in the background; code before the first await no longer blocks startup, and code that must run early moves to StartAsync or IHostedLifecycleService. On shutdown the host cancels stoppingToken and gives all stopping work a default 30-second ShutdownTimeout; work that ignores the token is cut off at the end of that window without even a log line.

8 Nov 2026 11 min 70
Running Work Outside the Request: Choosing Between Fire-and-Forget, BackgroundService, Hangfire and Quartz.NET
Backend PART 01

Running Work Outside the Request: Choosing Between Fire-and-Forget, BackgroundService, Hangfire and Quartz.NET

Work started with Task.Run inside a controller loses its DbContext when the request scope ends, swallows its exception silently and dies halfway through a deploy; it has to be handed to something the host manages. Five questions drive the choice: can the work be lost on restart, is it scheduled, do you need retries and a dashboard, how many instances run; the answers point to BackgroundService, Hangfire, Quartz.NET or a platform scheduler.

8 Nov 2026 10 min 71
Client Version Migrations: RabbitMQ.Client 6→7 (IModel to IChannel) and MassTransit 8→9
Backend PART 14

Client Version Migrations: RabbitMQ.Client 6→7 (IModel to IChannel) and MassTransit 8→9

Moving to RabbitMQ.Client 7 gave 5 compiler errors on the first build and 10 more on the second; the real risks are the ones the compiler misses: body lifetime, timeouts becoming cancellations and concurrency. Plus RabbitMQ 4.x rejecting mirroring policies, queue type mismatches, the AMQP 1.0 client, MassTransit 9 refusing to start without a license, v8 support ending on 31 December 2026, and the old Service Bus SDK mapping.

8 Nov 2026 13 min 84
Testing Message Queue Code: Testcontainers, the MassTransit Test Harness and Contract Tests
Backend PART 13

Testing Message Queue Code: Testcontainers, the MassTransit Test Harness and Contract Tests

Unit test the logic apart from the broker, test broker behavior against a real RabbitMQ with Testcontainers, and wait with signals and bounded polling instead of Task.Delay. The MassTransit test harness, the inactivity cost of negative asserts, a Total→TotalAmount rename silently turning into 0 under default JSON options, and the Microsoft.Testing.Platform setting xUnit v3 needs on .NET 10.

8 Nov 2026 12 min 67
Observability in Messaging: OpenTelemetry Trace Context, Queue Depth and Consumer Lag
Backend PART 12

Observability in Messaging: OpenTelemetry Trace Context, Queue Depth and Consumer Lag

Listen to RabbitMQ.Client 7's built-in ActivitySource and write the traceparent into Kafka headers yourself with a propagator; an order's journey through the API, RabbitMQ, Billing, Kafka and Notification then shows up as five spans in one trace. MessageId and CorrelationId in the log scope, the messaging.process.duration histogram, cardinality, queue depth and Kafka consumer lag, with real output.

8 Nov 2026 11 min 71
Transactional Outbox in .NET: EF Core, a BackgroundService Relay and the MassTransit/Wolverine Outbox
Backend PART 11

Transactional Outbox in .NET: EF Core, a BackgroundService Relay and the MassTransit/Wolverine Outbox

Write the message to an outbox table in the same transaction as the business data instead of to the broker, and let a BackgroundService relay pick rows with FOR UPDATE SKIP LOCKED and publish them with confirms. A real run of two instances publishing 200 messages exactly once and returning 201 while the broker is down; why the relay is at-least-once and unordered; MassTransit bus outbox, Wolverine and CDC.

8 Nov 2026 12 min 84
Idempotent Consumers and the Inbox: When the Same Message Arrives Twice
Backend PART 10

Idempotent Consumers and the Inbox: When the Same Message Arrives Twice

Stop a message from being processed twice with a unique constraint in the database, not with a check: write an inbox row keyed by MessageId in the same transaction as the business data, or apply ON CONFLICT to the business key. A real run of check-then-act issuing two invoices, inbox and upsert on PostgreSQL, side effects, dedupe cleanup and the MassTransit inbox.

8 Nov 2026 11 min 89
Managing Dead-Letter Queues: Finding, Inspecting and Reprocessing Poison Messages
Backend PART 09

Managing Dead-Letter Queues: Finding, Inspecting and Reprocessing Poison Messages

Run the DLQ like a work queue: read why each message failed from its headers, alert on growth, and after the fix send it back with a dry run, filters, a cap and your own replay counter. Real output shows RabbitMQ's x-death count not advancing on a client republish, Service Bus DLQ reason codes, a wrong original-topic bug in a Kafka DLT and MassTransit _error headers.

8 Nov 2026 12 min 70
Retry and Redelivery in Consumers: Immediate, Delayed and Exponential Backoff
Backend PART 08

Retry and Redelivery in Consumers: Immediate, Delayed and Exponential Backoff

Handle transient failures with a short in-memory retry and longer waits through the broker; never retry permanent failures, send them to the DLQ. Real output shows nack-requeue looping 8036 times in 5 seconds on RabbitMQ 4.4, TTL + DLX wait queues, the quorum queue's built-in delayed retry, scheduled retry in Service Bus, Kafka retry topics and MassTransit UseMessageRetry.

8 Nov 2026 17 min 82
Messaging with MassTransit: Consumers, Publish/Send and Broker Topology — v9 Licensing and Alternatives
Backend PART 07

Messaging with MassTransit: Consumers, Publish/Send and Broker Topology — v9 Licensing and Alternatives

MassTransit takes over connections, acks, serialization and topology, reducing a consumer to a single IConsumer<T>; the price is its own exchange conventions, an envelope format and, in v9, a commercial licence. We move Billing to MassTransit 8.5.12, show publish vs send, the resulting RabbitMQ topology and the envelope, see v9 refuse to start without a licence, and build a decision table across v8, Wolverine, Rebus, NServiceBus and Brighter.

8 Nov 2026 11 min 100
Message Contracts: Serialization, Versioning and Backward Compatibility
Backend PART 06

Message Contracts: Serialization, Versioning and Backward Compatibility

Keep contracts as records separate from domain entities, evolve them only by adding optional fields, turn on RespectRequiredConstructorParameters and RespectNullableAnnotations in System.Text.Json, and carry the version in a type header. Real output: with default settings a rename becomes a 0 TL invoice, a new enum value breaks old consumers, and Schema Registry rejects an incompatible schema with 409.

8 Nov 2026 10 min 77
Blog Map