Menu

Post image 1
Post image 2
1 / 2
0

Why You Should Avoid Promise.all() In AWS Lambda Durable Function

DEV Community·Rishi·22 days ago
#ifHCRypo
#aws#lambda#javascript#software#const#example
Reading 0:00
15s threshold
Cover image for Why You Should Avoid Promise.all() In AWS Lambda Durable Function

Rishi

Consider the example below:

const userPromise = context.step(async () => fetchUser());
const orderPromise = context.step(async () => fetchOrders());
const [user, orders] = await Promise.all([userPromise, orderPromise]);

Enter fullscreen mode Exit fullscreen mode

The above example can produce non-deterministic behaviours because the SDK assigns each operation a number to track it in the checkpoint log. If two operations start at the same time, their numbers can be assigned in different orders on different runs. On replay, the SDK might match the wrong checkpoint to the wrong step.

The safe way to run things concurrently is to use parallel or map with the Durable Lambda SDK.

Read More