How the Inherited Service Fits Together
One repository read at commit 4f1c9a2: 92 source files, 41 test files, a year of history and one incident note. It is a sound service with one fragile path.
The question, as asked in the composer
How is this service put together, and where is it fragile?
- Source
- A service your team is about to inheritGitHub repository
- Template
- Codebase Architecture ReviewSoftware
- Sections
- 17
- Exhibits
- 16
- Sources
- 1828 passages
- Citations
- 181
Sample reportThe sources, passages and figures in this report are invented for illustration.
Four facts in the code make one stuck charge stop the whole service, unseen
Two conditions cause the stall; two more decide that no one sees it and that it leaves damage behind. Each rests on lines in the captured commit.
In Brief
- 1
One worker runs every background job in turn, and the payment call it makes has no timeout.32
- 2
That combination stopped every job for 47 minutes on 14 March, with 1,312 waiting, while /health stayed green.57
- 3
A job interrupted by a restart is never picked up again; one charge was finished by hand.46
- 4
The worker is the busiest module and the only one with no tests; the three stale dependencies sit on the same path.91011
- 5
A timeout with an idempotency key, a lease on running jobs and a health check that sees the worker remove most of the risk.12
01Executive Summary
The service is a single process that answers requests and runs background jobs.1 Every request passes through one queue worker, so a stalled job holds up the whole service.3 The payment call that most jobs make has no timeout,2 the health check does not look at the worker,7 and the worker has no tests.10
This is not a hypothesis. On 14 March the gateway stopped answering and the queue grew to 1,312 waiting jobs over 47 minutes until someone restarted the process;5 one charge was left half-done and finished by hand.6 Three small changes remove most of that exposure. The rest of the code is in reasonable shape: strict types,15 54 per cent line coverage16 and a clean edge.
Exhibit 1
Three changes of small or medium effort remove most of the exposure
Each recommendation placed by the effort it takes and the risk it removes, judged from the code.
02Source Snapshot
Fact list
- Repository
- A service your team is about to inherit, captured at commit 4f1c9a2 on 2 October 2026.
- Files read
- 92 source files, 16,720 lines, the package manifest, the migrations, the pipeline and the Dockerfile.18
- Tests
- Forty-one test files.10
- History
- Twelve months: 318 commits by 7 authors.9
- Documents
- One incident note, 14 March 2026.5
- Not captured
- Production logs, dashboards, and the gateway’s own documentation.
Exhibit 2
The service in five numbers
03Key Findings
Writes return at once and do their work on the queue.20 One worker runs every job in turn,3 so a slow payment call, which has no timeout, can stop all the others.2 When the process stops mid-job, the job is never picked up again.4
Three of the ten most-changed files are in src/worker, and none of them is tested.910 The three dependencies over two years old are the queue library, the gateway client and the scheduler: the path that failed in March.11
Exhibit 3
Three passages of the queue worker decide how the service fails
src/worker/queue.ts as captured, with the lines this report rests on marked.
04Evidence Table
Comparison table
| Finding | Where | Read from | Strength |
|---|---|---|---|
| One worker for every job | src/worker/queue.ts, lines 41 to 583 | Code | Read in code |
| Payment call without timeout or retry | src/payments/client.ts, lines 88 to 962 | Code | Read in code |
| Running jobs are never reclaimed | src/worker/queue.ts, lines 60 to 744 | Code | Read in code |
| Health check blind to the worker | src/api/health.ts, lines 5 to 147 | Code | Read in code |
| A 47-minute stall happened | docs/incidents/2026-03-14-stall.md5 | Document | Documented |
| No idempotency key on the charge | src/payments/client.ts, lines 60 to 8712 | Code | Read in code |
| No worker tests | tests/10 | Listing | Read in listing |
| Three stale dependencies on the failing path | ci/deps-report.json11 | Report | Read in report |
| The export can starve the pool | export-report.ts and pool.ts1417 | Code | Inferred |
05Architecture Overview
One process registers the routes, opens the database pool and starts the queue worker.1 The code is layered as an edge (src/api), three domain modules (orders, billing, accounts), the worker, two integrations (payments, notify), the data layer and a shared library.
The layering mostly holds. But the worker reaches into orders and billing while both of them enqueue work for it, which makes three import cycles, and the API reads the database directly in four places, past the domain.20
Exhibit 4
The layers mostly hold; the worker is tied into the domain by three import cycles
Each module sits in its layer; a line is an import from one module into another, with the number of import statements. Lit lines run both ways; dashed ones skip a layer. The rule under each module is its line coverage.
Imports to src/lib are not drawn: every module uses it. The API also enqueues jobs directly, three times. Counts are import statements between top-level folders of src/.
Exhibit 5
Read across a row: what each module imports. The worker both uses and is used by orders and billing
Import statements from the row’s module into the column’s. A cell and its mirror both filled is a cycle.
06Module Map
Comparison table
| Module | Role | Files | Lines | Tests | Coverage |
|---|---|---|---|---|---|
| src/api | Routes, auth, validation; every write becomes a job. | 18 | 3,420 | 9 | 71% |
| src/orders | Orders and their items. | 14 | 2,880 | 8 | 68% |
| src/billing | Charges, invoices, proration, month-end run. | 11 | 2,310 | 5 | 44% |
| src/accounts | Sign-in, sessions, customers. | 9 | 1,640 | 6 | 77% |
| src/worker | The single queue worker and its seven job types.3 | 7 | 1,960 | None10 | 0% |
| src/payments | Calls the payment gateway; webhooks.2 | 4 | 820 | 2 | 31% |
| src/notify | Receipts and mail. | 5 | 610 | 3 | 58% |
| src/db | Connection pool, repositories, 31 migrations.17 | 16 | 2,140 | 6 | 62% |
| src/lib | Config, logging, retry helpers. | 8 | 940 | 2 | 49% |
| All of src/ | Nine modules | 92 | 16,720 | 41 | 54%16 |
07Runtime and Build Model
The build compiles to dist/ and the container runs one process.188 The worker lives inside that process,1 so the API and the jobs share one event loop and one pool of ten connections.17 The container’s health check calls /health, which only asks the database.7
On SIGTERM the process exits without waiting for the running job,13 and every deploy is such a stop. The pipeline lints, type-checks and runs the tests on every push, but no step starts the worker.23
Exhibit 6
A deploy is a stop, and a stop abandons the job in hand
What src/server.ts does when the process starts and when it is told to stop.
08Dependency Analysis
Comparison table
| Dependency | Role | Pinned | Age | Behind | Imported by |
|---|---|---|---|---|---|
| cronwheel | Scheduler | 0.9.8 | 38 months11 | 1 major | 1 file |
| jobline | Job queue | 1.4.2 | 31 months11 | 2 majors | 4 files |
| paylink-sdk | Payment gateway client | 2.0.1 | 27 months11 | 2 majors | 2 files |
| retrykit | Retry with backoff | 4.0.0 | 12 months | Current | notify and inventory sync, not payments11 |
| The other 18 | HTTP, database, validation, logging and the rest | Under two years24 | Current or one major |
Exhibit 7
The three oldest dependencies are the queue, the gateway client and the scheduler: the path that failed
Age of the pinned release of each of the 22 runtime dependencies, in months at the captured commit. Lit: over two years.
09Key Workflows
A write is two workflows. In the request, the route checks the session and the body, the orders module inserts the order and its job in one transaction, and the client gets 202 Accepted.2025 Later the worker polls the jobs table every 500 milliseconds,22 runs the charge and enqueues the receipt.3
A failed job is retried five times over 62 seconds and then marked dead.19 But a job that never fails, because its call never returns, never reaches that path: it stays running, and the worker with it.2 The incident note shows what that looks like.27
Exhibit 8
A job can leave every state but one: running, when its call never returns
The states the jobs table records and the transitions queue.ts makes. Dotted is a transition the code does not have.
Sources src/worker/queue.ts; src/payments/client.ts; docs/incidents/2026-03-14-stall.md; src/server.ts; src/db/migrations/; src/worker/jobs/index.ts9 passages
Exhibit 9
On 14 March the queue grew by about 28 jobs a minute for 47 minutes, and took 31 more to drain
Jobs waiting, from the incident note’s table, minute by minute after 14:00.
10Data Model and APIs
Thirty-one migrations build twelve tables; twenty-four of them can be reversed.28 The queue is a table in the same database, so a job and its order are written together, which is good; but the job’s payload names the order without a key, so nothing stops a job outliving its order.25
The API has forty-six routes, twenty-two of them writes and five open without sign-in.21
Exhibit 10
Twelve tables hold together by keys, except the queue: a job names its order but nothing binds them
The tables the 31 migrations create, with their key columns, joined where a foreign key exists.
Exhibit 11
Twenty-two of the forty-six routes write, and every write becomes a job
Routes registered in routes.ts by area and method.
11Code Quality Signals
Checklist
4not met1unclear3metof 8 checks
- Tests for the workerNot metNone in tests/.10
- Timeouts on outside callsNot metThe payment call and the export have none.226
- Graceful shutdownNot metExits without waiting for the running job.13
- Dependencies kept currentNot metThree are over two years old.24
- Reversible migrationsUnclear24 of 31 have a down step.28
- Tests overallMetForty-one test files, 54 per cent line coverage.16
- Strict type checkingMetstrict and unchecked index access on.15
- Checks on every pushMetLint, type check, tests.23
Exhibit 12
The module that changes most is the one with no tests
Each module by how often its files changed in a year and how much of it the tests run; the area of a circle is its size in lines.
Exhibit 13
Three of the ten most-changed files are in the worker, and none of the three is tested
File changes in twelve months for the ten busiest files; hatched files have no test.
12Risks and Maintainability Assessment
The single worker is the fragile point: one stuck job holds up the second half of every write.3 The likeliest stuck job is a charge, which has no timeout,2 and when it is cleared by a restart the job is orphaned.4 Nothing would tell an operator: the health check stays green.7
Adding a retry is not enough on its own. The charge carries no idempotency key,12 so retrying a request that did reach the gateway could charge twice. The order is a timeout, then a key, then a bounded retry.
Exhibit 14
Five of six failures reach the charges; only the database going down is caught by the health check
What each failure the code allows takes with it. A cross stops the capability; a half mark slows or loses some of it.
13System Context
Flow diagram
Exhibit 15
One process faces three callers and four systems; only the payment call can hang it
The service in its surroundings, as the code names them. The worker shares the process and the pool with the API.
14Request and Data Flow
Sequence diagram
Exhibit 16
A write is answered in one transaction; the charge happens later, on the one hop with no timeout
POST /orders followed through the code, message by message. The client has its answer before the charge is attempted.
15Key Figures
Metrics
16Open Questions
How long payment calls take in practice is not in the repository: the incident note records one hang, not a distribution.5 Whether the gateway honours an idempotency key, and for how long, is in its documentation, which was not captured.12 The month-end run has a fifteen-minute limit but no record of how long it usually takes.26
17Appendix
Sources
What the run captured and read: 18 sources, 28 passages. Each passage is quoted as it stands in the source; the marked words are the ones the report relies on.
src/server.tsCode fileTwo passages, cited 12 times
-
1Lines 12 to 30
The server registers the routes, opens the database pool and starts the queue worker.
-
13Lines 64 to 80
On SIGTERM the server stops accepting requests and exits; it does not wait for a job that is running.
-
src/api/routes.tsCode fileTwo passages, cited 12 times
-
20Lines 8 to 40
Every write route puts a job on the queue and returns at once.
-
21Lines 112 to 140
Forty-six routes are registered: twenty-four read routes and twenty-two write routes; five need no sign-in.
-
src/api/health.tsCode fileOne passage, cited 9 times
-
7Lines 5 to 14
GET /health returns 200 when the database answers a query; it does not look at the worker.
-
src/worker/queue.tsCode fileFour passages, cited 34 times
-
22Lines 20 to 34
The worker polls the jobs table every 500 milliseconds and takes the oldest job whose run_after has passed.
-
3Lines 41 to 58
A single worker takes jobs from the queue and runs each one to the end before it takes the next.
-
4Lines 60 to 74
Jobs marked running when the process stops are left as they are; nothing returns them to the queue.
-
19Lines 90 to 118
A failed job is retried up to five times, after 2, 4, 8, 16 and 32 seconds, and then marked dead.
-
src/worker/jobs/index.tsCode fileOne passage, cited 6 times
-
26Lines 1 to 36
Seven job types are registered. Five set timeoutMs; charge-order and export-report do not.
-
src/worker/jobs/export-report.tsCode fileOne passage, cited 3 times
-
14Lines 22 to 47
The export takes one connection from the pool and holds it while it streams every row of the month.
-
src/payments/client.tsCode fileTwo passages, cited 19 times
-
12Lines 60 to 87
The request body carries the order id and the amount; no idempotency key is set.
-
2Lines 88 to 96
The payment request is sent with no timeout and is not retried.
-
src/db/pool.tsCode fileOne passage, cited 9 times
-
17Lines 14 to 22
One connection pool of ten connections serves the whole service.
-
src/db/migrations/FolderTwo passages, cited 9 times
-
28Folder listing
Thirty-one migrations create twelve tables; twenty-four of them have a down step.
-
25007_jobs.sql, lines 1 to 18
The jobs table holds the queue: id, type, payload, state, attempts, run_after, locked_at, error. The payload is JSON and has no foreign key.
-
package.jsonCode fileTwo passages, cited 5 times
-
24Lines 10 to 34
Twenty-two runtime dependencies, three of them pinned to a version over two years old.
-
18Lines 4 to 9
build runs the compiler into dist/; start runs node dist/server.js.
-
ci/deps-report.jsonCode fileOne passage, cited 12 times
-
11Lines 1 to 212
For each runtime dependency: the pinned version, the date it was released, the latest version and the files that import it.
-
tests/FolderOne passage, cited 11 times
-
10Folder listing
Forty-one test files; none for src/worker/.
-
coverage/coverage-summary.jsonCode fileOne passage, cited 9 times
-
16Lines 1 to 64
Line coverage by folder at the last recorded run, 54 per cent overall; src/worker 0 per cent.
-
Commit historyCommit logOne passage, cited 7 times
-
9Twelve months to the captured commit
504 file changes in 318 commits by 7 authors; src/worker/queue.ts changed in 58 of them.
-
docs/incidents/2026-03-14-stall.mdMarkdown fileThree passages, cited 16 times
-
5Lines 1 to 12
At 14:02 the payment gateway stopped answering. The worker waited on the open request until the process was restarted at 14:49; 1,312 jobs were waiting by then.
-
27Lines 14 to 34, table 1
Jobs waiting, every five minutes from 14:00 to 15:20.
-
6Lines 36 to 41
One charge stayed marked running after the restart and was finished by hand the next day.
-
DockerfileCode fileOne passage, cited 4 times
-
8Lines 1 to 22
One image, one process: node dist/server.js, with a health check on GET /health every 30 seconds.
-
.ci/pipeline.ymlCode fileOne passage, cited twice
-
23Lines 1 to 48
Lint, type check and the tests run on every push; no step starts the worker.
-
tsconfig.jsonCode fileOne passage, cited twice
-
15Lines 2 to 14
strict: true; noUncheckedIndexedAccess: true.
-
In the App
Bring it up to date. Each makes a new revision.
