Practical .NET and Software Architecture Tips | Microsoft MVP
📰 The .NET Weekly: https://t.co/AOaa2Lvno7
▶️ YouTube: https://t.co/3anEBSnzZs
5 subscribers
Aug 10, 2023 • 8 tweets • 2 min read
Thinking about separate read/write databases?
Here's what you should know first.
Using separate read and write databases offers a range of benefits:
- Better performance
- Increased scalability
- Fault tolerance
Let's break them down.
𝗕𝗲𝘁𝘁𝗲𝗿 𝗽𝗲𝗿𝗳𝗼𝗿𝗺𝗮𝗻𝗰𝗲
By separating reads from writes, you can tune each database for its specific purpose.
Aug 9, 2023 • 6 tweets • 2 min read
What is the RIGHT way to use HttpClient in .NET?
HttpClient is an excellent abstraction and incredibly easy to work with.
Unfortunately, it's also easy to misuse, leading to problems like port exhaustion.
You need to know how NOT to use it.
If you think IHttpClientFactory will solve all your problems, you're only partly right.
Should you use named clients or typed clients?
Microsoft was kind enough to provide us with a set of best practices and recommended use for HttpClient.
Jul 25, 2023 • 9 tweets • 2 min read
What is a webhook?
Imagine this:
You have a website or an application, and you want it to automatically do things without you having to trigger them manually.
That's where webhooks come in!
Webhooks are like little messengers that allow one system to send a message or data to another system in real-time whenever a specific event happens.
It's like getting a notification on your phone when someone comments on your social media post or when you receive an email.
Jul 24, 2023 • 7 tweets • 2 min read
You don't need to start with Microservices.
Even if you're confident your application will be big enough to justify Microservices.
And here's why. 👇
Microservices come with a premium.
The Microservices premium:
- Team coordination
- Dealing with failure
- Eventual consistency
- Automating deployments
- Managing multiple services
And many other factors.
Jul 17, 2023 • 13 tweets • 3 min read
What are the SOLID principles? 🤔
As a .NET developer, I'm always looking for ways to improve the quality and maintainability of my code.
I want to share my experiences using the SOLID principles and how they've helped me create better code.
First, let's define what we mean by SOLID.
I've been using Clean Architecture for 5 years and counting.
Here's why I think it's amazing. 👇
Clean architecture isn't revolutionary.
But it is opinionated about how to structure your code.
It's just another form of layered architecture.
The core concept you need to grasp is the Domain.
Another way to think about Clean architecture is that it's a Domain-centric architecture.
The Domain is at the center of the architecture, and it's treated as the most essential part.
The other components support the Domain.
Jul 7, 2023 • 5 tweets • 2 min read
What is an API Gateway, and why do you need it for Microservices?
An API Gateway is a critical component of a Microservice-based system.
It acts as a reverse proxy and routes client requests to the appropriate services.
Here are 6 use cases for an API gateway:
- Request routing
- Load balancing
- Authentication
- Authorization
- Rate limiting
- Caching
But how can you build an API gateway in .NET?
You can use the YARP (Yet Another Reverse Proxy) library.
It's a level 7 HTTP proxy that integrates well with the .NET ecosystem.
Jun 21, 2023 • 5 tweets • 2 min read
Here are 3 tips for managing exceptions in C# 1. The proper way to rethrow exceptions
Sometimes, you need to rethrow the exception you just caught.
If you try to throw the exception instance, you will rewrite the stack trace.
Why is this bad?
Because you'll lose valuable information about the original exception.
Jun 20, 2023 • 11 tweets • 2 min read
Most people think Redis is just used for caching.
But it can do so much more!
Here are a few not-so-common use cases for Redis:
🔐 Distributed locks
Redis can be used as a distributed lock to ensure that only one process can access a resource. This can be useful in distributed systems where multiple processes might try to access the same resource simultaneously.
Jun 11, 2023 • 4 tweets • 1 min read
Side projects made me a better software engineer.
I tried to spend 30-45 minutes daily hacking away at my side project.
I focused on a few specific things:
- Software architecture
- New libraries
Sometimes, I would try to do everything wrong on purpose.
- Software architecture I didn't need
- New libraries I will never use
- Unnecessary complexity
- Overengineering
This wasn't a waste of time because I was on a mission.
My theory was that I would learn valuable lessons and build an instinct of what bad engineering looks like.
Jun 9, 2023 • 5 tweets • 2 min read
How do you add behavior to an existing class without modifying that class?
I know this sounds familiar.
I'll save you some time if you're brushing the dust off that design pattern book.
You need the Decorator pattern.
It's a structural design pattern that lets you add new behavior to objects by placing them inside of a wrapper object.
One use case is adding caching behavior as a decorator wrapping the underlying repository instance.
Jun 7, 2023 • 12 tweets • 3 min read
Why would you want to have separate read/write databases?
Here are a few things you should consider.
As software engineers, we always look for ways to improve our applications and systems. Right?
One technique that's often overlooked is using separate read and write databases.
And this offers a range of benefits:
- Optimized performance
- Increased scalability
- Fault tolerance
Let's break them down.
Jun 6, 2023 • 7 tweets • 2 min read
You shouldn't start with Microservices first if you want to succeed.
There's a better way to get there.
Here's what most Microservice success stories look like:
- Started with a Monolith
- Grew the system over time
- Monolith got too big
- Broken up into Microservices
Why is it so easy to fail if you start with Microservices?
It comes down to two things:
- Complexity
- Boundaries
Jun 5, 2023 • 6 tweets • 2 min read
Here's how you can use EF Query Splitting to improve performance.
I recently ran into an issue with Entity Framework Core.
The query I was running was constantly timing out.
After some digging, it turned out I was running into the problem of Cartesian Explosion.
So how did I solve the problem?
With the release of EF Core 5, we got a new feature called Query Splitting.
This allows us to specify that a given LINQ query should be split into multiple SQL queries.
May 31, 2023 • 13 tweets • 3 min read
Did you have a chance to work with the Outbox pattern?
If you're working with microservices, this is something to add to your toolkit.
So what is it?
The Outbox pattern is a solution for reliably publishing events in a distributed system.
Instead of publishing events directly, the Outbox pattern involves storing events in a separate table in your database.
And then having a background process read from that table and publish the events to a message broker.
Apr 19, 2023 • 10 tweets • 2 min read
What is a webhook?
Imagine this: You have a website or an application, and you want it to automatically do things without you having to trigger them manually.
That's where webhooks come in!
Webhooks are like little messengers that allow one system to send a message or data to another system in real time whenever a specific event happens.
It's like getting a notification on your phone when someone comments on your social media post or when you receive an email.
Apr 19, 2023 • 6 tweets • 2 min read
Do you want to get better at writing high-quality code?
Here is what I would do:
- Study Object-Oriented Programming and Design patterns
- Try to introduce all the possible abstractions
- Have an epiphany all of a sudden
- Strive to simplify my code
- Prosper
This process typically takes a few years, as you can see in the graph.
The graph shows a code complexity curve across years of programming.
We all have to go through the phases of complexity to learn to appreciate simple code.
Apr 17, 2023 • 4 tweets • 2 min read
What is the required keyword in C#?
It was added in C# 11.
When creating a new object instance, you can use the required keyword to indicate that a field or property must be initialized.
Have you used the C# required keyword already?
#dotnet
If you try to create a new object instance and don't assign a value to a required property, you'll get a compile error.
Before this, you had to use constructors with all the required values as parameters.
Mar 29, 2023 • 10 tweets • 2 min read
Most people think Redis is just used for caching.
But it can do so much more! Here are a few use cases for Redis:
🔐 Distributed locks
Redis can be used as a distributed lock to ensure that only one process can access a resource.
This can be useful in distributed systems where multiple processes might try to access the same resource simultaneously.
Mar 28, 2023 • 6 tweets • 2 min read
Performance problems are part of programming.
I've run into them a thousand times.
APIs, algorithms, databases - you name it.
Over time, I learned something:
Every single problem is a lesson.
It forces you to stop, think through, and find a way around it.
API output caching made no difference?
Try something else.
Linear complexity algorithm is worse?
Try something else.
Database index didn't help?
Try something else.
Mar 20, 2023 • 7 tweets • 2 min read
What's the easiest way to significantly improve API performance?
You can introduce a memory cache and get a 10x boost in speed.
Querying from a cache is typically faster than querying a database.
You're using a fast access path by querying with a given key.
A cache like Redis is commonly used.
However, do also consider the IMemoryCache in .NET.
It's excellent for simple caching scenarios or when you don't need a distributed cache.
Your only limit is the available RAM on the server.