← All work case study · contract · Cushon (NatWest) · pensions
Cushon pensions microservice
Cushon, a workplace-pension provider owned by NatWest, was breaking its core platform into services. The first was self-service employer sign-up: a new Symfony microservice that takes an employer from company lookup to a signed agreement, then hands over to the core platform by message. I was its second-highest committer and built much of the sign-up flow, front to back.
role senior engineer contract · 133 of 518 commits, 2nd of 11
stack Symfony 6 · PHP 8.1 Messenger · SQS · DynamoDB · Behat
scale 11 endpoints 27 Behat scenarios · ~317 unit tests
dates 2022 May to November 2022
1 · the problem
Sign employers up without a new service reaching into the old database.
An employer setting up a workplace pension has to be checked, give contribution, payroll and direct-debit details, and sign a participation agreement before the employer can exist in the core platform. That flow was moving into its own service as the first step towards a modular architecture.
The new service had to own its own data, talk to the core platform without sharing its tables, and be specified tightly enough that a pensions business could trust it with money.
2 · what I built
An employer-lead service: DDD layers, buses, and a signed agreement at the end.
The service is split into api, application, domain and infrastructure layers, with every action going through a command or query bus. My share was the lead lifecycle and the signing flow, and the portal pages that drive them. Alongside it, I led the migration of multiple master pension trusts.
- ▸The employer-lead API Create, read, list by user or by intermediary, update and complete a lead, each as a command or query with its own handler.
- ▸Domain objects for the money Payroll, contributions and direct debit as value objects and enums inside the lead aggregate, so an invalid lead cannot be built.
- ▸Agreement signing The service builds a signing envelope from the lead with an e-signature provider, stores the embed link and the document fingerprint, and records when signing completes.
- ▸Hand-over to the core platform Completing sign-up sends a command over a queue to the core platform, which creates the employer and answers on a return queue that links the new account back to the lead.
- ▸Sign-up pages in the portal The React and TypeScript portal pages for contributions, direct debit, payroll, account creation and signature, wired to the new service.
- ▸Less to protect Removed password storage from the service entirely, leaving accounts to the platform that owns them.
3 · decisions & trade-offs
Every choice had a cost. Here is what it was.
3.1 · Messages, not shared tables
- chose
- Commands over a queue, answers on a return queue
- because
- The new service never writes into the core platform’s database, and either side can be down for a while without losing a sign-up.
- cost
- Eventual consistency: a lead reads as submitted until the platform answers, and both sides must agree on a message schema.
3.2 · CQRS buses for every action
- chose
- Symfony Messenger command, query and event buses
- because
- Each handler is small and tested alone, and routing config decides whether a command runs in-process or travels over a queue.
- cost
- More classes per feature than a plain controller and service.
3.3 · Behaviour written down first
- chose
- Behat features, full coverage and mutation testing
- because
- In pensions the behaviour is the contract. Features describe it in plain language, and mutation testing proves the unit tests would notice if the code changed.
- cost
- Slower to start each change, and mutation runs take time.
3.4 · A document store for one aggregate
- chose
- DynamoDB through the SDK, no ORM
- because
- A lead is one aggregate read and written whole, by key. No relational mapping is needed, and capacity scales on its own.
- cost
- Access patterns, such as listing by user or by intermediary, have to be designed up front.
4 · testing & delivery
Specified in Behat, held to full coverage and mutation testing.
Features describe each journey in plain language: authorisation, the employer-lead steps, the company check and signing. Under them, unit tests cover the domain and the handlers, and Infection mutates the code to check those tests would fail if it changed.
Static analysis ran at two strict levels, and the whole suite ran inside the same containers that shipped.
- Behat
- 9 features · 27 scenarios
- PHPUnit
- ~317 tests in 90 files
- PHPStan
- level 6
- Psalm
- error level 1
- mutation testing
- Infection, 100% MSI target
- pipeline
- CircleCI → ECR → Beanstalk
5 · results
- my commits
- 133 of 518
- rank by commits
- #2 of 11
- endpoints in the service
- 11
- signing flow
- built end to end
- portal sign-up pages
- wired to the service
- passwords stored by the service
- none
- master trust migrations
- led
- contract
- May–Nov 2022
Carving a service out of a monolith, carefully?