MediatR is one of the best .NET libraries I ever worked with.
You can use it to implement the CQRS pattern to build fast and scalable applications.
The CQRS pattern separates the writes and reads in the application. This separation can be logical or physical and has many benefits.
MediatR implements the mediator pattern to solve a simple problem - decoupling the in-process sending of messages from handling messages.
You can extend MediatR's IRequest interface with a custom ICommand and IQuery abstraction. This allows you to define commands and queries in your system explicitly.
On the write side, I typically use EF Core and a rich domain model to encapsulate business logic.
On the read side, I want as little indirection as possible. Using Dapper with raw SQL queries is an excellent choice.
A few benefits of using MediatR:
- Organize your code around use cases (high cohesion)
- Easily implement cross-cutting concerns
- API endpoints become very thin
- Use cases are highly testable
If you want to learn more about CQRS with MediatR, I wrote a detailed guide.
You can read it here: https://t.co/vn29cheG9a
---
𝗣.𝗦. If you liked this, you will love The .NET Weekly newsletter. Join 49,000+ engineers to improve your .NET and software architecture skills.
Subscribe here → https://t.co/rfSiqQqvWH https://t.co/LQ6zlp91uS
📺 "Programmer's Guide to JDK Flight Recorder"
Great session on #JFR and how to use it in your @java apps; touching on recording control, custom events, analysis, testing, and more. Including honorable mention of #JfrUnit 🥳. Must-watch, by @jaokim2001!
https://t.co/Jm855tNZ0Z
This is probably the best reason WHY i use PostgreSQL if I don’t need anything very specific:
The rich ecosystem of extensions has solutions for probably everything I may need. I don‘t have to use new-niche-hype-database.
⚡ Database Tip
Sometimes, you have numerous rows, and you only want one for e.g. every customer. PostgreSQL's DISTINCT ON lets you do exactly that! With DISTINCT ON only the first row for every group is returned. Magic! 🧙♂️
https://t.co/0BFwJXTEXg
BRUTAL estas palabras del actor Anthony Hopkins:
Deja ir a la gente que no está lista para amarte.
Esto es lo más difícil que tendrás que hacer en tu vida y también será lo más importante.
Deja de tener conversaciones difíciles con personas que no quieren cambiar.
Deja de aparecer para las personas que no tienen interés en tu presencia.
Sé que tu instinto es hacer todo lo posible para ganar el aprecio de los que te rodean, pero es un impulso que roba tu tiempo, energía, salud mental y física.
Cuando empiezas a luchar por una vida con alegría, interés y compromiso, no todo el mundo estará listo para seguirte a ese lugar.
Eso no significa que tengas que cambiar lo que eres, significa que debes dejar ir a las personas que no están listas para acompañarte.
Si eres excluido, insultado, olvidado o ignorado por las personas a las que les regalas tu tiempo, no te haces un favor al seguir ofreciéndoles tu energía y tu vida.
La verdad es que no eres para todo el mundo y no todos son para ti.
Esto es lo que hace tan especial cuando encuentras a personas con las que tienes amistad o amor correspondido.
Sabrás lo precioso que es porque has experimentado lo que no lo es.
Hay miles de millones de personas en este planeta y muchas de ellas las vas a encontrar a tu nivel de interés y compromiso.
Tal vez si dejas de aparecer, no te busquen.
Tal vez si dejas de intentarlo, la relación termine.
Tal vez si dejas de enviar mensajes, tu teléfono permanecerá oscuro durante semanas.
Eso no significa que arruinaste la relación, significa que lo único que la sostenía era la energía que solo tú dabas para mantenerla.
Eso no es amor, es apego.
Es dar una oportunidad a quien no lo merece!
Tú mereces mucho más.
Lo más valioso que tienes en tu vida es tu tiempo y energía, ya que ambos son limitados.
A las personas y cosas que le des tu tiempo y energía, definirá tu existencia.
Cuando te das cuenta de esto empiezas a entender por qué estás tan ansioso cuando pasas tiempo con personas, actividades o espacios que no te convienen y no deben estar cerca de ti.
Empezarás a darte cuenta que lo más importante que puedes hacer por ti mismo y por todos los que te rodean, es proteger tu energía más ferozmente que cualquier otra cosa.
Haz de tu vida un refugio seguro, en el que solo se permiten personas “compatibles” contigo.
No eres responsable de salvar a nadie.
No eres responsable de convencerles de mejorar.
No es tu trabajo existir para la gente y darles tu vida!
Te mereces amistades reales, compromisos verdaderos y un amor completo con personas saludables y prósperas.
La decisión de tomar distancia con personas nocivas, te dará el amor, la estima, la felicidad y la protección que te mereces.❣️✍️
You should think 3.5 times before moving to a service-oriented architecture.
SOA generally increases the complexity before it provides the benefits.
However, once you’ve made the decision, the Strangler Fig pattern is one of the safest ways to make the move.
But how do you go about it?
3 things we used:
- Strangler Fig Pattern
- Change Data Capture (CDC)
- Kafka
Here’s how we made it work:
[1] Our monolithic application supported various features and stored all data in a MySQL database.
[2] We extracted Feature A into a separate service (Service A) with a new MongoDB database.
[3] Next, we built a CDC workflow with Debezium to move data from MySQL to MongoDB via Kafka.
[4] We placed a proxy (Nginx) to route read requests to Service A. All other requests went to the monolith including write requests to Feature A.
[5] Once we were satisfied with the read results from Service A, we migrated the writes as well
[6] In the end, feature A was no longer supported by the monolith. All requests went to Service A.
A couple of points to note about the whole process:
👉 Why Kafka?
Kafka provided some nice benefits such as:
Keeping the monolith and new service decoupled
Ordering guarantees
Great support with Debezium
👉 Why start with reads?
This was a critical system and we didn’t want to mess up the writes.
Moving the reads gave the team experience with the new architecture. It also allowed us to run comparisons between the monolith responses and the new service.
This is part of the safety-first approach of the Strangler Fig pattern.
So - what do you think about the Strangler Fig pattern?
And would you have done things differently?
ParadeDB has built an open-source PostgreSQL extension to do analytics very fast with high compression by using Parquet under the hood 😀
The most impressive thing? They are near the performance of ClickHouse 🔥
https://t.co/HnZU33Yfjy
What is Functional Testing in ASP .NET Core?
Functional tests allow you to test your API from a user's perspective.
This is why they're also called End-to-End tests.
The test traverses through your entire application.
You verify the response and HTTP status code.
Luckily, it's effortless to start writing functional tests in .NET.
You need to install the library that lets you spin up an in-memory instance of your application. This is the WebAppFactory in the slides.
What about external dependencies like databases and identity providers?
You can run most of them inside Docker, with Testconatiners, for example. The closer you are to a production-like setup, the more valuable function tests are.
If you have good abstractions in place, writing the tests is a piece of cake.
Create a request, send it with an HttpClient, and verify the response.
P.S. If you liked this, consider joining The .NET Weekly - my newsletter with 39,000+ engineers that teaches you how to improve at .NET and software architecture.
Subscribe here → https://t.co/LwZD0FZJMN
How often do you write functional tests in your project?
💡 Spring Boot Tip
Starting from Spring Framework 6.0.5 (Spring Boot 3.0.3) you can read content of the Resource into a String with `getContentAsString`:
Which latency numbers you should know?
Please note those are not precise numbers. They are based on some online benchmarks (Jeff Dean’s latency numbers + some other sources).
🔹L1 and L2 caches: 1 ns, 10 ns
E.g.: They are usually built onto the microprocessor chip. Unless you work with hardware directly, you probably don’t need to worry about them.
🔹RAM access: 100 ns
E.g.: It takes around 100 ns to read data from memory. Redis is an in-memory data store, so it takes about 100 ns to read data from Redis.
🔹Send 1K bytes over 1 Gbps network: 10 us
E.g.: It takes around 10 us to send 1KB of data from Memcached through the network.
🔹Read from SSD: 100 us
E.g.: RocksDB is a disk-based K/V store, so the read latency is around 100 us on SSD.
🔹Database insert operation: 1 ms.
E.g.: Postgresql commit might take 1ms. The database needs to store the data, create the index, and flush logs. All these actions take time.
🔹Send packet CA->Netherlands->CA: 100 ms
E.g.: If we have a long-distance Zoom call, the latency might be around 100 ms.
🔹Retry/refresh internal: 1-10s
E.g: In a monitoring system, the refresh interval is usually set to 5~10 seconds
Notes
-----
1 ns = 10^-9 seconds
1 us = 10^-6 seconds = 1,000 ns
1 ms = 10^-3 seconds = 1,000 us = 1,000,000 ns
--
Subscribe to our weekly newsletter to get a Free System Design PDF (158 pages): https://t.co/FIzCeaWsZV
How would you build a URL shortener in .NET?
URL shorteners have two core functionalities:
- Generating a unique code for a given URL
- Redirecting users who access the short link to the original URL
A URL shortener converts long URLs into more manageable, shorter versions. This is particularly useful for sharing links on platforms with character limits or improving user experience by reducing clutter.
You need to solve quite a few problems here:
- Generating unique codes
- Solving code generation collisions
- Having enough short URLs (codes)
- Making the system fast and scalable
Tomorrow, I'll show 38,674+ engineers how to build a URL shortener with .NET.
You can subscribe here: https://t.co/EHo2CbBDCS
P.S. The solution I'll show you will be able to generate 3,521,614,606,208 unique short URL combinations.
That's more than three and a half trillion short URLs. ♻️