# Effect vs Hono and Express: the verdict

- Published: 2026-11-25
- Updated: 2026-11-26
- Tags: Effect on the Backend, Effect, TypeScript
- URL: https://devtrillo.com/writing/effect-backend-18-effect-vs-hono-and-express/

> Part 18 of a series that builds one backend server on Node with Effect 4. The code is in [devtrillo/effect-on-the-backend](https://github.com/devtrillo/effect-on-the-backend/tree/part-18), and this part is the `part-18` tag.

[Part 17](/writing/effect-backend-17-shipping-it/) ended with the question the series started from: was Effect worth it, against the Hono or Express server I'd have written without it? Arguing that from memory is easy and proves nothing, so I wrote that server. Twice. The repo now has a `compare/` folder with the same users API in Hono and in Express 5. I ran the same requests and the same failures against all three.

My answer: for this server, Effect paid for itself, but not where I expected. It didn't save lines; it cost about 40% more of them. Hono with `@hono/zod-openapi` got closer on types than I'd guessed. Where Effect won was the failures I didn't think to write code for, and two of those took down both plain servers.

## The two other servers

`compare/` is what I'd build today without Effect, written carefully, by someone who'd just spent 17 parts learning where this server breaks. Hono 4.13.14 with `@hono/zod-openapi` 1.6.3 for the contract and the OpenAPI document, and Express 5.3.0 with plain zod 4.6.7. Both share the same modules underneath:

- `pg` 8.23.1 with a hand-written `transaction()` helper and a small migration runner that takes the same `LOCK TABLE` as Effect's migrator
- a `fetch` retry loop: 2 s per attempt, backoff from 250 ms with jitter, and 5 s for the whole send
- a welcome queue with one worker and the same 10-second drain as [part 14](/writing/effect-backend-14-background-jobs-and-graceful-shutdown/)
- the OpenTelemetry Node SDK with auto-instrumentation, and the welcome job carrying its request's context like [part 15](/writing/effect-backend-15-logs-spans-and-metrics/)
- `/health`, `/ready`, the same JSON error bodies, and a SIGTERM handler that closes things in order

Left out on both sides: the RPC routes from part 16, the token CLI, and the in-memory `Users` that only the tests use. The Effect side is still on `effect` 4.0.5, as it has been since part 1 (4.0.6 is out).

## Lines

Non-blank lines that aren't comments, imports included, same 120-column formatting:

| What                                                          | Effect  | Hono    | Express |
| ------------------------------------------------------------- | ------- | ------- | ------- |
| schemas, queries, migrations                                  | 156     | 94      | 94      |
| mail retries, queue, drain                                    | 96      | 87      | 87      |
| contract, validation, auth, routes, probes, startup, shutdown | 150     | 104     | 80      |
| telemetry setup                                               | 6       | 8       | 8       |
| **total**                                                     | **408** | **293** | **269** |

Effect is the longest, by 115 lines over Hono and 139 over Express. A lot of that is overhead you can see from across the room. Imports alone are 61 lines against 26, because every module pulls from `effect`, `effect/sql`, `effect/http-api` and its neighbours by name. The three migrations are three 13-line files where `pg` wants three SQL strings. Every service ends with the same `Context.Service` class and `static layer`, and every SQL method ends with some form of `Effect.catchTags({ SqlError: Effect.die, SchemaError: Effect.die })`.

The middle row surprised me. The retry loop and the drain came out at nearly the same size in plain TypeScript, and the queue file is 58 lines in both. Here's the retry half:

```ts title="compare/src/mailer.ts (excerpt)"
export async function sendWelcome(user: Welcome, signal: AbortSignal): Promise<void> {
  const deadline = AbortSignal.any([signal, AbortSignal.timeout(5000)])
  for (let attempt = 0; ; attempt++) {
    let wait = 250 * 2 ** attempt * (0.8 + Math.random() * 0.4)
    try {
      const response = await fetch(`${config.MAIL_URL}/send`, {
        method: "POST",
        headers: { "content-type": "application/json", "idempotency-key": `welcome-${user.id}` },
        body: JSON.stringify({ to: user.email, subject: "Welcome", text: `Hi ${user.name}!` }),
        signal: AbortSignal.any([deadline, AbortSignal.timeout(2000)]),
      })
      if (response.ok) return
      if (!transient.has(response.status) || attempt === 3) throw new NotRetried(`mail service answered ${response.status}`)
      wait = Math.max(wait, Number(response.headers.get("retry-after") ?? 0) * 1000)
    } catch (error) {
      if (error instanceof NotRetried || deadline.aborted || attempt === 3) throw error
    }
    await sleep(wait, undefined, { signal: deadline })
  }
}
```

It works. I ran it against part 13's fake mail service with every attempt hanging, and it did what Effect's version does. But each line in it is a decision I have to re-read to trust. And the `signal` parameter is only there because the drain needs to cut a send off. [Part 13](/writing/effect-backend-13-timeouts-retries-and-schedule/)'s version says the same thing in four piped calls, and the cut-off comes from interruption, so `welcome` never mentions shutdown at all. Same line count, less to get wrong.

## Same requests, three servers

I ran 18 requests against each server. Most answers matched, because I wrote the plain versions to match. The differences that were left:

| Request                          | Effect                 | Hono                                             | Express                                    |
| -------------------------------- | ---------------------- | ------------------------------------------------ | ------------------------------------------ |
| `GET /users/1/` (trailing slash) | 200 Ada                | 404 (Hono routes are strict by default)          | 200 Ada                                    |
| `POST /users` with broken JSON   | 400, `BadRequest` JSON | 400, plain text `Malformed JSON in request body` | 400, `BadRequest` JSON (my error handler)  |
| `POST /users` as a form          | 415                    | 415, plain text                                  | 400, "expected object, received undefined" |
| `GET /nope`, `POST /users/1`     | 404, empty body        | 404, plain text                                  | 404, an HTML page                          |

The Hono row is the one I'd fix first. The route's OpenAPI document says a 400 is a `BadRequest` JSON object, and `defaultHook` turns every zod failure into one. A body that isn't JSON fails before zod sees it, though. The client gets text its generated types say can't happen.

All three answer `GET /users/99999999999999999999` with a 500, because 20 digits don't fit in `bigint`. Part 9 left that bug in on purpose; none of the three caught it.

## The failures I didn't write code for

This is where the comparison stopped being close.

### Postgres restarts

I warmed each server with one request so its pool held an idle connection, then ran `docker restart` on the database. Three seconds later:

```text title="after docker restart, Postgres 18"
effect   alive   GET /users/1  200  0.018 s
hono     DEAD    curl: connection refused
express  DEAD    curl: connection refused

node:events:505
    throw er; // Unhandled 'error' event
error: terminating connection due to administrator command
```

Postgres closes every connection when it shuts down. `pg`'s pool turns an error on an idle connection into an `'error'` event on the pool, and an `EventEmitter` with no `'error'` listener throws. The pool's README warns about it under `error`, as "common when your PostgreSQL server shuts down, reboots", or the network drops. The fix is one line, and it's in `compare/` now:

```ts title="compare/src/db.ts (excerpt)"
export const pool = new pg.Pool({ connectionString: config.DATABASE_URL })
// Without a listener, an idle connection dropped by Postgres (a restart, a failover) kills the process.
pool.on("error", (error) => console.warn("idle database connection lost", error.message))
```

I didn't write it the first time, after 17 parts on this exact server. Effect's `@effect/sql-pg` has no event emitter to forget about; its log didn't even mention the restart.

### A client that gives up

Part 10 showed Effect rolling a transaction back when the client disconnects. I put the same three-second `pg_sleep` between the two `INSERT`s in all three servers, as a scratch edit. Then I posted a user with `curl --max-time 1`:

| Server  | Access log | `users` row | `user_events` row | Welcome mail |
| ------- | ---------- | ----------- | ----------------- | ------------ |
| Effect  | 499        | no          | no                | not sent     |
| Hono    | 201, 3 s   | yes         | yes               | sent         |
| Express | nothing    | yes         | yes               | sent         |

Hono logged a 201 to a client that was long gone. That's a choice more than a bug: the user does exist, and you could argue the work should finish. The trouble is that the client can't tell. It got no answer, so it retries. On the plain servers that retry would create a second user with a new id, and a second welcome mail, because the idempotency key is per user id. `@hono/node-server` gives each request an `AbortSignal`, but `pg`'s `query()` has no option that takes one, so getting Effect's behaviour means wiring `pg_cancel_backend` by hand.

**Quiz:** A client posts a user, and gives up after one second. The transaction takes three. What does the Hono server leave behind?

- Nothing: the transaction rolls back when the socket closes
- A user, an event row, and a welcome mail on its way
- A user without an event row

**Answer:** A user, an event row, and a welcome mail on its way — Measured: 201 in Hono's log after 3 s, both rows committed, mail sent. If the client retries, it gets a second user.

- Not "Nothing: the transaction rolls back when the socket closes": That's Effect's behaviour, from interruption. pg has no idea the HTTP client left, so the queries run on and COMMIT.
- Not "A user without an event row": Both INSERTs are in one transaction, and nothing interrupts it, so both commit.

### SIGTERM with mail stuck in the queue

This one was a draw. Four posts with the mail service hanging, then SIGTERM half a second later:

```text title="all three servers, fake mail always hanging"
draining welcome queue { queued: 3 }
welcome mail not sent  (5 s deadline)
welcome mail not sent  (5 s deadline)
welcome mails not sent { users: [ '12' ] }
welcome mail cut off { user: '11' }
exited after 10.06 s (Effect), 10.08 s (Hono), 10.07 s (Express)
```

Same lines, same order, same exit. Plain TypeScript can drain a queue properly. It just has to be told every step. There's an `ended` flag, an `EventEmitter` to wake the worker, and a `setTimeout` that aborts the controller the mailer listens to. Then a shutdown function calls it all in the right order. In Effect the order falls out of which layer was built first.

### Tracing

All three exported a trace for a `POST /users` to my OTLP sink:

| Server  | Spans | What the names say                                                                                               |
| ------- | ----- | ---------------------------------------------------------------------------------------------------------------- |
| Effect  | 15    | `Authorization.bearer`, `Tokens.verify`, `Users.create`, `sql.transaction`, `WelcomeJobs.send`, `Mailer.welcome` |
| Hono    | 22    | `POST`, `pg.query:INSERT`, `pg-pool.connect`, eight `dns.lookup` and `tcp.connect`, my one `WelcomeJobs.send`    |
| Express | 29    | the same, plus seven `middleware` and `request` spans                                                            |

The plain traces have more spans and less in them. Nothing says which function a query came from unless you write `tracer.startActiveSpan` around it, which is what `Effect.fn("Users.create")` has been doing since part 2. Auto-instrumentation also needs to load before everything else, so the servers start with `node --import ./src/telemetry.ts`, and that file has to register an ESM loader hook first. The OpenTelemetry instrumentation README lists one more condition: the instrumented modules must not be bundled. Part 17 bundles the server with esbuild. I didn't build a bundled plain server to watch it fail, but Effect's spans are ordinary function calls in the bundle, so the question never comes up.

## What the compiler caught

I broke each server's source on purpose and ran `tsc`:

| Mistake                                         | Effect | Hono (`zod-openapi`)    | Express                 |
| ----------------------------------------------- | ------ | ----------------------- | ----------------------- |
| create handler without the auth middleware      | error  | error                   | compiles                |
| returns a status the contract doesn't list      | error  | error                   | compiles                |
| returns `id` as a number, contract says string  | error  | error                   | compiles                |
| `UserNotFound` thrown and never mapped to a 404 | error  | compiles, becomes a 500 | compiles, becomes a 500 |

I expected Hono to lose more of this table. Typed `createRoute` middleware put `user` on the context, so removing it broke `c.get("user")`, and the response map rejected both the undeclared status and the wrong shape. What it can't see is a thrown error: `findUser` returns `Promise<User>` whether or not it throws, so forgetting the `catch` is fine as far as TypeScript knows. In Effect, `UserNotFound` sits in the error channel until something declares or handles it ([part 6](/writing/effect-backend-6-typed-errors-become-status-codes/)).

Express caught nothing. `res.locals.user` is `any`. My first version of its `GET /users/:id` also reported a bad id with `path: []` instead of `["id"]`. I'd validated the param on its own instead of as an object, and nothing flagged that either.

**Quiz:** Your Hono handler calls findUser, which throws UserNotFound, and you forget the try/catch. What happens?

- tsc fails, because 404 is in the route's responses
- It compiles, and a missing user becomes a 500
- It compiles, and zod-openapi turns it into a 404

**Answer:** It compiles, and a missing user becomes a 500 — Hono's error handler answers Internal Server Error. The types can't see what a function throws.

- Not "tsc fails, because 404 is in the route's responses": Declaring a 404 only allows returning one. Nothing requires it, and a thrown error isn't in Promise<User>.
- Not "It compiles, and zod-openapi turns it into a 404": zod-openapi validates input and types output. It doesn't map exceptions.

## Memory and speed

Effect costs memory. Idle, after startup, with telemetry off everywhere:

|                                   | Effect     | Hono       | Express    |
| --------------------------------- | ---------- | ---------- | ---------- |
| idle RSS                          | 148–201 MB | 48–102 MB  | 73–98 MB   |
| with the OpenTelemetry SDK loaded | (same)     | 146–148 MB | 143–167 MB |

Part of the Effect number is `effect/http-api` loading its Scalar and Swagger assets up front, which part 5 measured at about 50 MB. The OpenTelemetry Node SDK costs the plain servers about as much, so once tracing is on, the gap mostly closes.

I also ran ApacheBench, 10,000 `GET /users/1` at concurrency 20. Over several runs each, all three landed somewhere between 1,250 and 3,560 requests a second, and which one was fastest changed from run to run. My laptop had other work on it, so I'm not calling a winner. None of the three is slow enough to choose on speed.

## The verdict

Where Effect paid for itself on this server:

- **Failure defaults.** An interrupted request rolls back, a dropped connection doesn't kill the process, and the drain runs in layer order. I knew about all of these and still forgot the pool listener.
- **Errors and dependencies in the types.** Hono matched it on the contract. Only Effect caught the error nobody handled, and part 11's `CurrentUser` couldn't be forgotten either.
- **Tracing that names my code and survives a bundle.**
- **Tests without a database.** [Part 12](/writing/effect-backend-12-testing-handlers/) swapped `Users.layer` for the in-memory one. With module-level `pool` imports in `compare/`, I'd be reaching for module mocks or a real Postgres.

Where it was ceremony: 40% more lines, 61 of them imports. The `catchTags(... Effect.die)` repeated on every SQL method. Part 8's `Request<"Requires", Users>` that wouldn't compile until I changed where the handlers got `Users`. Four modules (`effect/http`, `effect/http-api`, `effect/sql`, `effect/observability`) marked unstable, so the repo pins exact versions and every bump is a decision. And the vocabulary. Someone joining this codebase needs Learning Effect before they can review a pull request. Someone joining the Hono version needs an afternoon.

What I'd pick: for a CRUD API where each request is a query or two and nothing runs in the background, Hono with `@hono/zod-openapi`, plus `pool.on("error")`. It gets you most of the contract safety for a fraction of the learning. Once the server has work that outlives a request, like a queue, retries, a drain, or anything that has to stop cleanly, I'd start in Effect. Each of those cost me a page of careful code in `compare/`, and the page was the easy part. The hard part was the line I didn't know to write.

## Run it

```sh
git clone https://github.com/devtrillo/effect-on-the-backend
cd effect-on-the-backend
git checkout part-18
docker compose up -d --wait
docker compose exec db createdb -U app compare
cd compare
npm install
DATABASE_URL=postgres://app:change-me@localhost:5432/compare PORT=3002 npm run hono
```

`npm run express` starts the other one. The Effect server runs from the repo root with `npm start`, as before. To see the first failure for yourself, delete the `pool.on` line in `compare/src/db.ts`, make one request, and restart the database.

That's the series. Eighteen parts, one server, and now two more copies of it to argue with.
