AsyncLocalStorage
A Node.js feature that keeps a value available to all code running for one request, even across await and callbacks, without passing it as an argument.
In more detail
Middleware calls asyncLocalStorage.run(context, next), and any function later in that request can read the correlation ID, user or tenant from the store. Unlike a global variable, concurrent requests each see their own value.
Related terms
- request context — The information attached to a single request, such as who made it, when and from where, that code or access policies check while handling it.
- correlation ID — A unique value attached to one request and passed along everywhere it goes, so its logs and traces can be found together.
- multi-tenancy — One running system serving several separate customers, called tenants, while keeping each one's data and settings apart.
- async and await — Language keywords for writing code that waits for slow work, such as a network call, without blocking a thread.
Taught in
- Multi-Tenant Identity: Tenant Isolation & Middleware — Production Full-Stack Engineering
- Structured Logging & Correlation IDs: Context Stitching — Production Full-Stack Engineering