At some point, a program needs two things that do not depend on each other.
Fetch the user.
Fetch the invoices.
Those can run at the same time.
The plain version
const [user, invoices] = await Promise.all([ fetchUser(userId), fetchInvoices(userId),]);This runs both at once.
There is also no type for what failed.
Both fetches can fail in different ways. The rejection carries one of them.
If fetchUser rejects, Promise.all rejects too.
fetchInvoices keeps going in the background. Nothing cancels it.
The caller gets an unknown error in its catch.
If you want the user even when invoices fail, you switch to Promise.allSettled and unpack the results by hand.
Run both
const program = Effect.all({ user: fetchUser(userId), invoices: fetchInvoices(userId),});This gives one Effect with both results.
Effect.Effect< { user: User; invoices: Invoice[] }, UserNotFound | InvoiceApiDown, UserRepo | InvoiceClient>;That type is doing useful work.
It shows the combined success, combined errors, and combined requirements.
Parallel when it is safe
Some work must be sequential.
You cannot fetch invoices for a user id before you have parsed the user id.
But once you have the id, independent calls can run together.
const program = parseUserId(input).pipe( Effect.flatMap((userId) => Effect.all({ user: fetchUser(userId), invoices: fetchInvoices(userId), }), ),);The mistake: assuming all means parallel
Effect.all runs one Effect at a time by default.
The examples above fetch the user first, then the invoices.
To run them together, say so:
const program = Effect.all( { user: fetchUser(userId), invoices: fetchInvoices(userId), }, { concurrency: "unbounded" },);Now both start together.
If one fails, Effect interrupts the other.
Nothing keeps running in the background.
concurrency also takes a number.
{ concurrency: 2 } runs at most two at a time. That helps when the list is long and the API has a rate limit.
How to spot it: an Effect.all with no concurrency option, in code you expected to run in parallel.
Without the option, the code is still correct.
It is only slower than you expected.
The nice part
In normal async code, I often have to inspect the Promise.all shape and then think about errors separately.
Effect keeps the shape together.
Success. Error. Requirements.
The same three slots again.

