Tag related to Dotnet Core

Parallel vs Asynchronous: Understanding the Difference in C# (Using Bread Making)

When working with C#, developers often face two important concepts:

  • Asynchronous programming (async/await) – Best for waiting on external tasks (e.g., network requests, file operations).
  • Parallel programming (Parallel.ForEach) – Best for executing multiple tasks simultaneously (e.g., CPU-heavy computations).

To explain this, let’s use the example of baking bread.

Asynchronous Programming (async/await) – A Single Baker Handling Tasks Efficiently

Imagine you are baking bread alone. The process involves several steps:

  1. Mix the ingredients → You wait for the dough to come together.
  2. Proof the dough → You wait for it to rise.
  3. Shape the dough → You actively work on it.
  4. Bake the bread → You wait for it to cook.

Each step has periods of waiting. Instead of just standing around, you do other work—like washing dishes or preparing another meal—while waiting.

One Use Case for TPL

TPL is a set of libraries from Microsoft that can be used for parallel processing, basically it is a set of high level tools that can make your code run in parallel. TPL is not a panacea for parallel processing, mainly because you don’t always need parallel processing, but when you need it, it can be a life-saver.

The system

The system was built with a simple purpose, to consume and process events delivered by Kafka. The events were published, in Avro format, by a separate system, let’s call it producer. Essentially the events represent a course of actions, which are used to produce our model. Eventually that model is publicly exposed through an API (not HTTP). Everything was built using C# on dotnet core and ran on a docker container on linux hosts.

Multi-stage building with Docker

Docker supports a feature, where you can create multiple containers with a single dockerfile and at the same time share the contents between the containers. This feature gives you the possibility of having multi-stage builds and opens one significant spot for creating repeatable builds.

The idea behind it is simple, you can have multiple FROM statements inside the same Dockerfile. Each FROM statement can use different images, therefore defines it’s own dependencies and allows you to connect the containers from one base to the other by using COPY --from=0or COPY --from=previous-stage.

ASP.NET & Docker Experience

Introduction

Docker is system for creating and managing lightweight linux containers, which has become very popular in the enterprise computing business.

ASP .NET is a framework/platform from Microsoft, mainly used in building web applications. At the moment is on version 4.6.1 (stable) and version 5 is waiting around the corner. Version 5 is a completely re-done, its structure and mentality mimics the frameworks like Django, Flask or Express, which are small and provide you with basic functionality for web development. The rest is provided upon request by adding packages.