Want to build fast and scalable applications?
Here's how the CQRS pattern can help.
The CQRS pattern separates the writes and reads in the application.
This separation can be logical or physical - and this is where many developers get it wrong.
CQRS has many benefits:
- Complexity management
- Improved performance
- Scalability
- Flexibility
- Security
My preferred approach is starting with logical CQRS.
I have one database and separate flows for writing and reading data.
You can design a data model fine-tuned for each operation.
If you want to learn more about CQRS, I wrote an in-depth article explaining how to implement each step.
You can read it here: https://t.co/gxeJJ5HLA1
---
✍️ Would you use CQRS?
♻️ Reshare if you liked this.
Here are 4 ways you can use the HttpClient in .NET:
- Create an instance every time (bad)
- Use the IHttpClientFactory (better)
- Use a named HttpClient (great)
- Use a typed HttpClient (also great)
So, what is the best approach?
I can tell you what I prefer using - typed clients.
And sometimes I will even go for Refit.
The simplest way to work with the HttpClient is to create a new instance every time.
But this is susceptible to port exhaustion.
I created a complete guide for how to use the HttpClient in .NET.
Read it here: https://t.co/8YBI1ru2hr
---
P.S. If you liked this, consider joining The .NET Weekly - my newsletter with 41,000+ engineers that teaches you how to improve at .NET and software architecture.
Subscribe here → https://t.co/lQs9X4ci61
Breaking the Monolith at Twitch - what the journey looked like. 🚀
I spent this weekend researching Twitch's migration to Microservices.
The Twitch team is a fan of Martin Fowler, who said:
"Almost all the successful microservice stories have started with a monolith that got too big and was broken up."
There's a lot of nuance packed into this simple sentence.
Here's how the Twitch team defines monoliths and microservices.
Monoliths are a single build of unified code. Every service and feature in the code is built into one large system. They usually share the same server, file system, and database. Monoliths work well for smaller teams that need to move fast.
Microservices, on the other hand, are smaller modules of code, each with its function and focus. Every module is a separate application that usually lives on its server, communicating with each other through APIs. Microservices work well for large organizations that must set boundaries between smaller groups.
Do you notice how the reasoning behind microservices is organizational?
Let's dig deeper.
Twitch started as a monolith using Ruby on Rails. This worked well for some time, allowing them to develop new features quickly.
For Twitch, the biggest issue was dealing with performance bottlenecks.
The first bottleneck was scaling the chat functionality as the number of users on the platform grew and gaming became more popular. The first microservice was a Pubsub server written in Go. This paved the way for introducing microservices to the rest of the system.
The existing monolith application had various challenges:
- Single deploy pipeline for everyone
- Difficult to trace errors to their owners
- Slow database queries
- Merge conflicts
But here's the most interesting part about the story.
The team didn't move large parts of the API out into microservices. Instead, they extracted individual API endpoints.
Twitch added an NGINX proxy in front of the API. The proxy's role was to redirect a small percentage of traffic to the new API running in microservices.
With the new proxy in place, the process to migrate endpoints was defined:
- Develop your new microservice
- Replicate the old endpoint in the microservice
- Configure NGINX to send a percentage of traffic to the new endpoint
- Verify metrics and keep increasing traffic until 100%
This is a brilliant process, as it reduces the risk because we're only dealing with a single endpoint.
Still, the migration lasted for several years.
P.S. What do you think of Twitch's migration to microservices?
---
P.S. If you liked this, consider joining The .NET Weekly - my newsletter with 40,000+ engineers that teaches you how to improve at .NET and software architecture.
Subscribe here → https://t.co/apmm3XxWUL
Are you working on moving the Monolith to Microservices architecture?
You can use the Strangler Fig pattern.
The name of this pattern is a bit funny.
It's an analogy for a plant that starts as a vine growing alongside an older, established tree. Eventually, it grows and replaces the original tree.
So, what does this have to do with moving to Microservices?
The Strangler Fig pattern identifies parts of the monolith that we can pull out. You can think of it as a group of related features.
You take the related features and pull them out of the monolith.
Once the system is stable and everything works as expected, repeat this process. Find another set of features, and pull them out of the monolith.
After a few iterations, the individual services replace the entire monolith.
But there's a better way to do this.
It's called the Modular monolith architecture.
Here's how it can make switching to Microservices faster: https://t.co/oaeOu3Kraw
---
P.S. If you liked this, consider joining The .NET Weekly - my newsletter with 36,000+ engineers that teaches you how to improve at .NET and software architecture.
Subscribe here → https://t.co/zeSWQFMIk8
You won't become a senior software engineer with 2 years of experience.
And that's not to discourage you - quite the opposite.
I've seen a lot of talk about becoming a senior engineer quickly.
It only takes 1-2 years. Right?
And it probably does - for some people (power to them).
But this isn't a realistic timeline for the majority of developers.
It took me ~4.5 years to get promoted to a senior role.
I'm willing to bet I solved many more problems than my peers with the same experience. I worked damn hard - and experience compounds.
So how can you get there faster?
It's simple: you need to become more competent.
You need skills.
A whole lot of skills.
✅ More skills = bigger impact
✅ More skills = better job
✅ More skills = better pay
You need to be hungry for knowledge:
- Books
- Articles
- Courses
- Workshops
- Conferences
But you don't want to be just "book" smart.
The real difference maker is real-world experience.
You need to work on challenging projects. And you need to do that for an extended period of time. And I promise you, you'll get promoted sooner or later.
This is why some folks get promoted to senior roles in 2 years.
They worked their butts off to get there.
They also sacrificed many things along the way.
Things you might not be willing to sacrifice.
You choose your own path (fast or slow).
But don't forget to enjoy it.
---
P.S. If you liked this, consider joining The .NET Weekly - my newsletter with 35,000+ engineers that teaches you how to improve at .NET and software architecture.
Subscribe here → https://t.co/VYvfbj4G2h
Don't build Microservices without an API Gateway.
An API Gateway is a critical component of a Microservice-based system.
But what is an API Gateway in the first place?
It acts as a reverse proxy and routes client requests to the appropriate services.
API Gateways hide the internal implementation details from the clients.
The client only has to call the API Gateway.
You can also use an API gateway for:
- Request routing
- Load balancing
- Authentication
- Authorization
- Rate limiting
- Caching
Did you know you can build an API gateway in .NET?
You can use YARP, a level 7 HTTP proxy.
YARP stands for Yet Another Reverse Proxy.
It's easy to integrate it with existing .NET features.
For example, you can use the built-in authentication and rate limiting.
P.S. If you got value from this post and want to improve your software architecture skills, subscribe to The .NET Weekly - my newsletter with 35,000+ engineers.
Subscribe here → https://t.co/nbp02JQy95
What do you use to build API Gateways?
𝗪𝗵𝗮𝘁 𝗶𝘀 𝗩𝗲𝗿𝘁𝗶𝗰𝗮𝗹 𝗦𝗹𝗶𝗰𝗲 𝗔𝗿𝗰𝗵𝗶𝘁𝗲𝗰𝘁𝘂𝗿𝗲?
I first heard about Vertical Slice Architecture from Jimmy Bogard.
He's also the creator of some popular open-source libraries like MediatR and Automapper.
Vertical Slice Architecture was born from the pain of working with layered architectures.
Layered architecture forces you to make changes in many different layers to implement a feature.
Vertical slices take a different approach:
"Minimize coupling between slices, and maximize coupling in a slice."
All the files for a single use case are grouped inside one folder.
So, the cohesion for a single use case is very high.
This simplifies the development experience.
It's easy to find all the relevant components for each feature since they are close together.
If you're building an API, the system already breaks down into commands (POST/PUT/DELETE) and queries (GET).
By splitting the requests into commands and queries, you're getting the benefits of the CQRS pattern.
Vertical slices narrowly focus on a single feature.
This allows you to treat each use case separately and tailor the implementation to the specific requirements.
For example:
- GET - EF Core to DTO
- GET - Dapper raw SQL to DTO
- POST - Repository + Rich domain model
- DELETE - EF Core ExecuteDeleteAsync
Vertical slices give you the flexibility to choose the ideal implementation.
What do you think about VSA?
Tomorrow, I'll show 30,872+ engineers how to use the Vertical Slice Architecture.
📌 Join free here: https://t.co/xip45XpWuB
How do you 𝘀𝗵𝗶𝗽 𝗰𝗵𝗮𝗻𝗴𝗲𝘀 𝗯𝗹𝗮𝘇𝗶𝗻𝗴𝗹𝘆 𝗳𝗮𝘀𝘁 in modern systems?
My team used this approach to ship updates to production within minutes.
I'm talking about having a solid CI/CD system in place.
Hold up, but what is CI/CD?
CI/CD is a method to increase the frequency of delivering new features by adding automation to your software development workflow.
Continuous Integration ("CI") refers to the automation process of syncing new code to a repository.
Any new changes to the application code are immediately built, tested, and merged.
Continuous Delivery, or Deployment ("CD"), refers to the process of automating the deployment part of the workflow.
When you merge a change into the repository, this step takes care of deploying those changes to the production environment (or any other environment).
There are many tools you can use to implement this:
- Jenkins
- Azure DevOps
- GitHub Actions
- Octopus Deploy
You will typically write a YAML file describing your deployment workflow.
And then, you automate it by connecting it with Git.
What's your experience with CI/CD pipelines?
What is an 𝗘𝗻𝘁𝗶𝘁𝘆 in 𝗗𝗼𝗺𝗮𝗶𝗻-𝗗𝗿𝗶𝘃𝗲𝗻 𝗗𝗲𝘀𝗶𝗴𝗻?
This is one of the first concepts you will encounter when learning about DDD.
Think about it like this:
- Do I need to track this object throughout the application's lifetime?
If the answer is yes, you need a way to identify this Entity at any point.
This is why an Entity is defined by its ID.
Another key aspect of Entities is that they also contain behavior.
Entities encapsulate and protect the most important business rules and invariants.
You implement this by exposing methods that allow you to manipulate state and trigger side effects.
I hope this post demystified this concept for you.
Give it a repost if you enjoyed it. ♻️
What are your thoughts about DDD entities?
What is middleware in ASP .NET Core?
Middleware allows us to introduce additional logic before or after executing an HTTP request.
There are three approaches to creating middleware:
- With Request Delegates
- By Convention
- Factory-Based
Do you know how each one works?
Google is using Modular Monoliths. 🔥
They just open-sourced a framework for building and deploying distributed applications called Service Weaver.
Service weave allows you to write modular monolith applications and deploy them as microservices.
C# Tip 💡
How do you control concurrency in your application?
The lock statement in C# allows you to synchronize access to a block of code, ensuring that only one thread can execute it at a time.
#dotnet