Runtime & concurrency
Reveal answer and reasoning
Choose a small immutable correlation value and define where its scope begins, how nested operations inherit or replace it, and where previous state is restored. Avoid storing an entire mutable request graph when only an identifier is needed. Use explicit parameters for dependencies whose ownership or variation should be visible in an API rather than relying on ambient lookup everywhere.
Test nested scopes, child slot replacement, shared-object mutation if any references remain, failure cleanup, and deliberately detached work. Keep output ordering controlled by gates rather than assuming thread changes. The wrong design calls AsyncLocal a safe global, stores mutable authorization or business state there, and assumes context copying deep-clones it. Flow propagation can carry useful tracing data, but it does not supply authorization, automatic resource disposal, or a complete retention policy for objects captured by operations that outlive the original request.
What a strong answer covers
- Use a narrow immutable value with explicit scope.
- Test nested replacement and cleanup.
- Separate ambient propagation from authorization and object ownership.
Common pitfall
Storing a whole mutable request in AsyncLocal and assuming automatic isolation and cleanup.
Follow-up questions
- How would detached work receive or omit correlation?
- How would you investigate retained ambient object graphs?
Self-review
Choose what to revisit. These marks are your own assessment and are separate from lesson completion.