Dotnet

How to use task-coalescing in C# to stop doing wasteful work

Lester Sanchez
The post discusses a common inefficiency in multithreaded applications where multiple tasks redundantly compute the same result, particularly in scenarios involving high-concurrency requests to remote servers. It introduces the task-coalescing technique, which ensures that only one task fetches the data while others reuse the result, reducing wasteful work. Using .NET’s Lazy<T> and ConcurrentDictionary<TKey, TValue>, the example implementation demonstrates how to achieve this efficiently, mitigating issues like cache stampedes and improving performance with minimal code changes.

How to do logging in .NET AWS Lambda functions

Lester Sanchez
The article outlines four ways to send logs to AWS Cloudwatch from a .NET Lambda function. It covers ILambdaContext.Logger, a basic option for simple logging; LambdaILogger, which integrates with Microsoft’s ILogger for richer features but has limitations with parameter serialization; Serilog, a highly customizable library for structured logging and control over log formats; and AWS Lambda Powertools, a straightforward utility tailored for AWS Lambda with built-in X-Ray trace correlation. The choice between these methods depends on the need for simplicity or advanced customization.