Chapter 01 · The trouble with waiting01 / 21

Signup, the slow way

Alice signs up for your app. The signup handler saves her to the database, then does the polite follow-up work: it sends a welcome email, makes a thumbnail of her avatar, and records the signup in analytics.

It does all of it synchronously. Each call waits for the one before it, and only then does the handler answer. Watch the timeline under it: Alice stares at a spinner for about 1.6 seconds, waiting on work she doesn’t care about.

The animation is slowed down so you can follow each call. The milliseconds in the readouts are what a real user would wait.

signup.jsin the real world
app.post('/signup', async (req, res) => {
const user = await db.users.insert(req.body);
await email.sendWelcome(user); // ~600 ms
await thumbs.resize(user.avatar); // ~800 ms
await analytics.track(user); // ~120 ms
res.status(201).json(user); // only now!
});