Mocking API’s at scale

Working on national systems such as the National Booking Service that enables everyone to book a coronoavirus vaccine has been a highlight of my career. As with any system it’s had its challenages and finding the time to innovate to solve those challanges hasn’t been easy. That said, there is one innovation that will definately be of use when things get back to normal. If you’ve ever needed to mock an API dynamically at scale, then read on.

The Challenge

The Eligibility checking aspect of the National Booking Service is built using two key API’s. The first, delivered by NHS Digital is the Personal Demographics Service — NBS was the first service to use this API and wouldn’t have been able to deliver as easily in the timescales without the support of the team to make it live. PDS lets us look up and check an NHS Number. The second is the National Immunisation Service, an API that keeps track of who is eligible for the vaccine and what doses have been given. NIMS needs an NHS Number to find your record. As with any system, data is always a challenge, we needed to ensure we had the records in PDS lined up with NIMS. Secondly, we had to ensure we could deal with the anticipated traffic which meant we needed both PDS and NIMS to be available for performance testing. Generally the environments for performance testing were only available in the evenings meaning a lot of lates nights. We needed a way of mocking out PDS and NIMS so we could run during the day.

All of the API’s for nhs.uk use Azure API Manager so mocking the NIMS API was easy as the response didn’t need to be dynamic. PDS was harder, we needed to query based on NHS Number and by name / DoB etc. Plus, we needed to do this for 1.5 million records. How do you mock that may dynamic records!?

The Solution

We had the NHS Numbers and demographic information from PDS as we needed this to run the performance tests. We’d played with creating a mock API early in the development, but this was based on JSON files and was a bit fiddly. We’ve also implemented CosmosDB as part of the NBS, so how could we use Cosmos with a function infront of it to provide the mock. Was there a simpler solution. Yes!

Azure API Management has a sample policy that enables a call to CosmosDB to be be made directly without the need for any code. We loaded CosmosDB with all our perf testing data as a simplified FHIR message, all 1.5 million records and created two policies in API Manager.

CosmosDB Storage of PDS entries

The policy above allows a point read of CosmosDB and returns the JSON. This has transformed our ability to run performance testing during the day and having our data lined up across the different API’s. We are now extending this further to allow dynamic updates to the data to better cater for all the testing scenarios.

There is an excellent post from Anthony Chu that covers the API Management / CosmosDB link in more detail here.

Lead Architect at nhs.uk