07 / 17

What is Promise chaining?

Difficulty: 5/10
sequential async, error propagation, return values

Promise chaining is the process of linking multiple promises sequentially using the .then() method, so that the result of one operation becomes the input for the next. We should return the new promise from the old one on which then will be called.

javascript

Scenario Questions

0-2 years experience

  1. 1You need to fetch user data, then their posts, and finally render them. How would you use promise chaining to ensure each step runs after the previous one completes?
  2. 2If you return a value from a .then() callback, what does the next .then() receive? Show a short code example.

2-5 years experience

  1. 1We have a function that returns a promise, but sometimes it rejects. How would you structure a chain to retry the operation once before propagating the error?
  2. 2During a recent feature, the UI stopped updating after a network call. The code uses promise chaining; what are common pitfalls that could cause the chain to break, and how would you debug it?

5-8 years experience

  1. 1Our service aggregates data from three microservices sequentially using promise chains, but latency is high. How would you refactor the chain to improve performance while preserving order where needed?
  2. 2Explain how unhandled rejections propagate in a long promise chain in a production Node.js service, and what strategies you’d employ to ensure errors are logged and the process stays healthy.

8+ years experience

  1. 1We are migrating a legacy callback‑heavy codebase to async/await, but some modules still rely on promise chaining for backward compatibility. How would you design a wrapper or abstraction to allow both styles to coexist without introducing subtle bugs?
  2. 2Across multiple teams, there’s inconsistency in how promise chains handle errors (some swallow errors, others rethrow). As a staff engineer, how would you establish a standard, and what tooling or lint rules would you introduce to enforce it?

Follow-up Questions

  • What happens if you forget to return a promise inside a .then?
  • How does a thrown error inside a .then differ from a rejected promise?
  • Can you rewrite a promise chain using async/await and what changes?
Share

Share via WhatsApp, X, Facebook, LinkedIn or copy link. Open Graph preview enabled.