SShortSingh.
Back to feed

How to Manage NestJS Transactions Without Passing EntityManager Through Every Layer

0
·1 views

A common but silent bug in NestJS applications causes database rows to persist even after a transaction rollback, because some repositories never receive the EntityManager and run queries on a separate connection outside the transaction. Manually threading the EntityManager through every service method and repository interface forces TypeORM-specific code into the domain layer, breaking clean architecture principles. The article proposes a roughly 60-line solution using Node.js AsyncLocalStorage, allowing the transaction to open once at the controller level while repositories automatically enlist themselves without receiving any parameters. The author also addresses three side-effects of this transaction boundary design: external network calls holding database connections too long, failure-logging records being rolled back alongside the errors they document, and nested execute calls creating independent transactions rather than true nested ones. Each problem is presented alongside a concrete fix, making the overall approach suitable for production-grade NestJS applications with a repository pattern.

Read the full story at DEV Community

This is an AI-generated summary. ShortSingh links to the original source for the complete article.

Discussion (0)

Log in to join the discussion and vote.

Log in

Related stories

0
ProgrammingHacker News ·

The system behind how IKEA names its thousands of products

IKEA follows a structured internal naming system to assign names to its wide range of products. Different product categories are linked to specific naming themes, such as Scandinavian place names, personal names, or nature-related words. This approach helps maintain consistency across IKEA's global catalog while reflecting the brand's Swedish heritage. The naming conventions vary by product type, ensuring each item carries a name that aligns with its category. The system has been a long-standing part of IKEA's product development process.

0
ProgrammingHacker News ·

Turbovec: Open-Source Rust Library Brings Fast Quantized Vector Search

Turbovec is a new open-source library written in Rust, inspired by Google's TurboQuant approach to vector search. It aims to deliver high-performance, quantized similarity search for vector data. The project was shared on Hacker News, where it garnered initial attention from the developer community. The library is publicly available on GitHub under the repository of developer RyanCodrai. No further technical details or benchmarks were provided in the initial announcement.

0
ProgrammingDEV Community ·

S&P Downgrade Threatens Oracle's Wisconsin Data Center Over Utility Credit Rule

S&P Global downgraded Oracle's issuer credit rating to BBB- on July 9, placing it just one notch above junk status, while citing OpenAI as a credit risk within Oracle's $638 billion backlog and projecting a $42 billion free cash flow deficit for fiscal 2027. Wisconsin's Public Service Commission had previously approved a rule requiring utility customers rated below A- to post financial guarantees before receiving electricity, and allowed a deadline to revisit that rule to lapse on July 10 without action. As a result, Oracle's subsidiary co-developing the roughly one-gigawatt Port Washington data center campus faces over $100 million per year in cash deposits or letters of credit just to purchase power. Oracle had already filed a lawsuit against the commission on June 19, arguing the credit threshold was unlawful, but its rating has since moved further from the required threshold rather than closer. At the heart of the standoff is the financial risk to Wisconsin ratepayers if Oracle exits, since the proposed gas plant being built to serve the campus is a multi-decade, billion-dollar asset backed by demand that is only a few years old.

0
ProgrammingDEV Community ·

How Redis Streams and Idempotent Workers Fix Broken AI Agent Polling Loops

Most production AI agents rely on polling loops that repeatedly query databases or APIs at fixed intervals, a pattern that breaks down at scale. This approach causes problems including high tail latency, cascading API rate limits, wasted compute resources, and race conditions when multiple workers process the same task simultaneously. An event-driven architecture using Redis Streams addresses these issues by having the environment push enriched event payloads to agents instead of agents continuously pulling for work. Consumer groups distribute incoming events across workers, while idempotency checks using atomic Redis operations prevent duplicate processing. The result is a reactive, low-latency workflow that reduces infrastructure overhead and ensures reliable execution under heavy load.