The Problem: You are firing off Task.Run() in a controller and hoping it finishes, but the server kills it. The Fix: Implement BackgroundService. It’s the reliable, built-in way to run long-running processes. public class Worker : BackgroundService { protected override async Task ExecuteAsync(CancellationToken stoppingToken) { while (!stoppingToken.IsCancellationRequested) { // Your logic here await Task.Delay(1000, stoppingToken); […]
Author: ErcanOPAK
Hot Reload Configuration with IOptionsSnapshot
The Problem: You changed a value in appsettings.json, but the app keeps using the old value until you restart the server. The Fix: Inject IOptionsSnapshot<T> instead of IOptions<T>. It reads the config file every time the request is made. public class MyService { private readonly MySettings _settings; // Updates immediately when json changes! public MyService(IOptionsSnapshot<MySettings> […]
Parse JSON directly in T-SQL
The Problem: You stored a JSON blob in a text column and need to query a specific property without writing a backend script. The Fix: Use OPENJSON or JSON_VALUE (SQL Server 2016+). — Extract specific property from JSON column SELECT JSON_VALUE(SettingsColumn, ‘$.theme’) AS UserTheme FROM UserPreferences WHERE JSON_VALUE(SettingsColumn, ‘$.isActive’) = ‘true’;
Finding Duplicates Instantly in SQL
The Problem: You have duplicate rows in a table and you need to identify them immediately. The Fix: Use GROUP BY and HAVING to isolate records appearing more than once. SELECT Email, COUNT(*) as Count FROM Users GROUP BY Email HAVING COUNT(*) > 1;
Splitting Lists with .Chunk()
The Problem: You need to process a list of 10,000 items in batches of 100, but writing the for loop math is tedious and error-prone. The Fix: Since .NET 6, you can simply use LINQ’s .Chunk(). var heavyItems = GetHugeList(); // Instantly splits into arrays of 100 items foreach (var batch in heavyItems.Chunk(100)) { ProcessBatch(batch); […]
Stop Allocating Memory with Span
The Problem: You need to parse a large string (like a substring), but String.Substring() creates a new string object in memory every time, hurting performance. The Fix: Use Span<T>. It provides a type-safe, memory-safe representation of a contiguous region of arbitrary memory without allocation. string text = “2023-10-25”; // Instead of text.Substring(0, 4) which allocates… […]
The Null Coalescing Assignment Operator (??=)
The Problem: You are writing verbose if (variable == null) checks just to assign a default value. The Fix: Use ??= to assign a variable only if it is currently null. It makes your initialization logic incredibly clean. // Old way if (myList == null) { myList = new List<string>(); } // Life-saver way myList […]
Visual Studio — “Build Succeeded” but App Uses Old DLLs
🧠 Cause Incremental build cache mismatch. ✅ Fix Clean + Rebuild entire solution.
WordPress — Revisions Table Can Explode Database Size
Every save creates a revision. ✅ Fix Limit revisions in wp-config.php.
Windows 11 — Virtualization Eats RAM Silently
Hyper-V / WSL reserves memory. ✅ Tip Limit VM memory explicitly.
Windows 11 — Game Mode Can Hurt Dev Performance
Optimizes GPU, throttles background tasks. ✅ Fix Disable Game Mode for dev machines.
AJAX — Missing credentials Breaks Auth Cookies
fetch(url) ❌ Problem Cookies not sent. ✅ Fix credentials: “include”
JavaScript — setInterval Drifts Over Time
Intervals accumulate delay. ❌ Result Timers become inaccurate. ✅ Fix Use recursive setTimeout.
HTML5 —
Without width/height Causes Layout Shift
CLS hurts SEO and UX. ✅ Fix Always specify dimensions.
CSS — display: none Skips Layout but Breaks Animations
Hidden elements cannot animate. ✅ Alternative Use: visibility: hidden;
.NET Core — UseDeveloperExceptionPage in Production Is Dangerous
Leaks: stack traces internal paths config values ✅ Rule Enable only in Development.
.NET Core — Model Validation Runs Before Your Code
Even before controller logic. 🧠 Why it matters Expensive validations slow APIs Happens on every request ✅ Tip Keep DTOs small and flat.
SQL — DELETE Without Batching Locks Tables
Large deletes = blocking. ✅ Safe pattern DELETE TOP (1000) FROM Logs Loop until rows = 0.
SQL — OR Conditions Can Disable Indexes
WHERE Status = 1 OR Status = 2 ❌ Effect Index seek → index scan. ✅ Fix Rewrite with IN or UNION.
C# — using Blocks Can Hide IO Bottlenecks
using var stream = File.OpenRead(path); 🧠 Problem Dispose can block while flushing buffers. ✅ Rule Avoid heavy IO inside tight loops.
C# — string.Concat Is Faster Than string.Format
Formatting is expensive. ✅ Faster var s = string.Concat(a, “-“, b); ❌ Slower string.Format(“{0}-{1}”, a, b); Impact: hot paths, logging, serialization.
C# — readonly Fields Don’t Make Objects Immutable
Many devs assume readonly = immutable. ❌ Reality readonly protects the reference, not the object. readonly List<int> items = new(); items.Add(1); // allowed ✅ Fix Use immutable collections when needed.
Performance — Measuring in Dev Lies to You
Local machines hide: IO waits CPU contention GC pressure ✅ Rule Benchmark under production-like load.
Observability — Logs Without Correlation IDs Are Noise
Distributed tracing without IDs is guesswork. ✅ Fix Propagate correlation IDs across services.
Kubernetes — Liveness Probes Can Kill Healthy Pods
Aggressive probes restart working services. ✅ Rule Liveness = is it stuck? Readiness = can it receive traffic?
Docker — Layer Order Can Double Image Size
Bad order: COPY . . RUN npm install ✅ Fix Copy manifests first, install, then source.
Git — Line Endings Break Builds Cross-Platform
CRLF vs LF causes: failing tests weird diffs ✅ Fix Use .gitattributes.
JSON — Schema Validation Prevents Silent API Breakage
Clients change. APIs break quietly. ✅ Fix Validate JSON against schema before processing.
Cancellation — Passing Token Is Not Enough
You passed CancellationToken…but didn’t observe it. ✅ Rule Check ThrowIfCancellationRequested() in loops.
Async Streams — IAsyncEnumerable Saves Memory
Instead of loading everything: await foreach (var item in stream) Benefits Lower memory usage Faster first response Ideal for large datasets












