ArrayPool in C#: Reusing Buffers Wisely
If you've ever profiled a hot path and seen allocation spikes from new byte[...], you're not alone.
I hit this while parsing lots of small payloads in a loop. The code was simple and readable, but GC ...
Struct Marshalling in C# Interop
If you've ever called native code from C#, you've probably had that "wait, why is this crashing?" moment.
Most of the time, the bug isn't your business logic. It's marshalling. The managed and unmanag...
AsyncLocal in C#: Context That Flows
AsyncLocal<T> is one of those features I ignored for way too long.
When I finally needed correlation IDs to show up everywhere (controllers, services, logs, background work), passing one more paramete...
Practical Guide to Lazy in .NET
I used to initialise everything at startup because it felt "safe." Then I'd profile cold starts and realise half those objects were never used on most requests.
Lazy<T> fixed that for me. It's simple,...
EF Core Change Tracking Performance Pitfalls
EF Core's change tracker is one of those features you barely notice when things are small, and then suddenly everything feels slower once your app grows up.
I've been bitten by this a few times. The f...
JSON Versioning & Schema Evolution
If you've ever shipped an API and then needed to rename a property two weeks later, you already know the pain: clients don't upgrade all at once.
That means your JSON contract has to evolve without br...
C# Ref Structs & Stack-Only Types
I used to hear “stack-only type” and immediately assume it was some niche trick for people benchmarking everything down to the nanosecond.
Turns out, ref struct and Span<T> are useful way earlier than...
HybridCache in ASP.NET Core
HybridCache in ASP.NET Core
I like caching right up until I have to explain which cache API we should use this time.
IMemoryCache is nice and fast. IDistributedCache is nice and shared. Then you end u...
goto in C#: Almost Always a Mistake
The goto statement in C# is one of those features that makes experienced developers visibly uncomfortable when they see it in a code review. There's a reason for that.
Let's talk about why goto exists...
Getting Started with .NET Aspire Local Dev
Getting Started with .NET Aspire Local Dev
If you’ve ever stitched together 2–5 local services, a database, and a queue just to test one feature, you already know the pain. .NET Aspire makes that setu...
Reusing CancellationTokenSource with TryReset
If you're creating a lot of short-lived operations, repeatedly allocating CancellationTokenSource instances can add avoidable pressure.
In .NET, CancellationTokenSource.TryReset() lets you reuse a sou...
Guard Clauses in C# for Cleaner Methods
Nested if blocks make methods harder to read than they need to be. By the time you reach the main logic, you're scrolling past layers of defensive checks.
Guard clauses flatten that structure and make...
Request Timeout Middleware in ASP.NET Core
Long-running requests are rough on everyone. Users wait, reverse proxies retry, and thread pool pressure quietly ramps up.
ASP.NET Core's request timeout middleware gives you a clear upper bound so sl...
Compiled Queries in EF Core
EF Core already caches query plans internally, so for many apps that's enough. But if you've got very hot paths called constantly, compiled queries can trim extra overhead.
They're especially useful i...
Optimistic Concurrency in EF Core
Most business systems eventually hit a "last write wins" bug. Two users edit the same record, both click save, and the second write silently overwrites the first.
EF Core's optimistic concurrency supp...