How to solve dual write problem in NestJS?

There are only two hard things in Computer Science: cache invalidation and naming things. – Phil Karlton Well, let’s add another one to the list: consistency. In distributed systems or modular monoliths, maintaining data consistency across multiple services or modules can be quite a challenge. Let’s imagine we have an e-commerce application with two services: OrderService and PaymentService. The OrderService is responsible for confirming orders, while the PaymentService handles the payment processing. Here’s a simplified example in NestJS: ...

September 15, 2024 · 9 min

A Smart Way to Create Scalable Web Sockets in NestJS

A long time ago, I found myself in a situation where I had to create a scalable system that could be capable of handling hundreds of simultaneous connections at not very high cost, and with reasonable, but not instant time of response. My first thoughts? Let’s move all create/edit/delete actions to the queue and notify users if their actions succeeded or not via WebSocket. But back then, I hadn’t much experience with WebSockets in production, so my first step was to investigate how it works with the help of tutorials, stack overflow, and other sources. ...

October 28, 2023 · 8 min