Now I want one small program.
Not a production app.
Not an architecture diagram.
Just enough code to see the pieces touch.
The flow
The program will:
That is a real shape.
The plain version
export async function GET(request: Request) { const input = new URL(request.url).searchParams.get("id") ?? "";
try { const id = parseUserId(input); const user = await fetchUser(id); return Response.json(user); } catch (error) { if (error instanceof UserNotFound) { return new Response("User not found", { status: 404 }); } if (error instanceof InvalidUserId) { return new Response("Invalid user id", { status: 400 }); } throw error; }}It works.
It is also the version most people write first.
Nothing checks that list.
If fetchUser learns a new way to fail, this still compiles. The new error falls through to throw error.
The core program
const getUserResponse = (input: string) => parseUserId(input).pipe( Effect.flatMap(fetchUser), Effect.map((user) => Response.json(user)), Effect.catchTag("UserNotFound", () => Effect.succeed(new Response("User not found", { status: 404 })), ), );Read it straight down.
Parse.
Fetch.
Turn success into JSON.
Handle one known error.
The type tells the truth
After handling UserNotFound, the type might still say:
Effect.Effect<Response, InvalidUserId, UserRepo>;That means:
- success:
Response - error:
InvalidUserId - requirement:
UserRepo
There is still work to do before running it.
We need to decide what bad input means.
We need to provide UserRepo.
Run it at the edge
export async function GET(request: Request) { const id = new URL(request.url).searchParams.get("id") ?? "";
const program = getUserResponse(id).pipe( Effect.provide(UserRepoLive), Effect.catchTag("InvalidUserId", () => Effect.succeed(new Response("Invalid user id", { status: 400 })), ), );
return Effect.runPromise(program);}The runner appears once.
At the edge.
That feels right.
The mistake: running with errors left over
Effect.runPromise accepts a program with errors still in the slot.
If one of them happens, the promise rejects.
At the edge, that usually means a 500.
Before you run, hover program. Here it should read:
Effect.Effect<Response, never, never>;Nothing left to handle. Nothing left to provide.
If the error slot is not never, decide what each error means first.
A 400, a 404, a retry, or a log line.
Each one should be a choice you can see.
What I learned from the first pass
Effect is not one idea.
It is a stack of small ideas:
- describe work before running it
- make errors visible
- make dependencies visible
- compose the happy path without losing the failure path
- run the program at the edge
I still have a lot to learn.
But now I can read the first line of the map.
Effect.Effect<Success, Error, Requirements>;That is enough to keep going.

