Skip to content

Case study

Whale Report

Lead backend engineer, Sep 2025 to Oct 2026, on Ocean Wise's whale-sighting platform, which turns sightings into real-time alerts for mariners, and on its versioned public partner API.

Client
Ocean Wise
Dates
2025 to 2026
Live
app.ocean.org (opens in a new tab)
merged PRs as lead on the backend
460
merged PRs across the Ocean Wise org
559
endpoints in the v2 partner API
14

The problem

Ships strike whales. Whale Report, Ocean Wise’s platform, collects whale sightings from the public through its app and from partners such as hydrophone networks and researchers, and turns them into real-time alerts for mariners, so a ship can slow down or steer clear.

The backend behind it has to do three hard things at once. Partners need a stable, documented API they can build against. Each sighting comes with rules about who may see it: some are only for real-time safety alerts, others can be published as open data. And sightings go out of date: a whale heard an hour ago is a warning, one heard last week is history.

My role

Lead backend engineer from September 2025 to October 2026, on the NestJS service behind the apps and the partner API, working with Ocean Wise’s own engineers. I wrote nearly all of Partner API V2, and I set up a shared AI-assisted workflow for the whole engineering team.

What I built

  • Partner API V2. A new, versioned API under /v2 that partners build against: sightings, submitting reports, alerts and reference data. Its OpenAPI specification is generated from the code, checked automatically, and copied to Ocean Wise’s API documentation whenever it changes, so the docs always match what the server actually does.
  • Sharing scopes. Every record has a sharing level, ranked from most restricted to most open, and each partner’s API key decides which levels it can read. When a partner sends in a report, it says which level the report has, rather than the report taking on whatever the partner can read. Reports of the same whale are grouped into one sighting, and a sighting’s sharing level can only become more restricted, never more open. The check and the write happen in one database statement, so two reports arriving at the same moment can’t both slip past it.
  • Expiry. A partner can say how many hours a sighting stays relevant. Expired sightings are left out of every read, and the expiry time also tells other systems when to delete their copies.
  • Paging and retries. Large results come back a page at a time. The token for the next page records the filters and the caller’s sharing level, and fixes the time window, so results can’t shift or change sharing level partway through. Partners can’t see inside the token. Sending the same report twice has the same effect as sending it once, so a partner whose request failed can simply retry.
  • Getting the map right. MySQL expects coordinates latitude first; GeoJSON, the standard format for map data, expects longitude first. I moved the reads and the code that writes alerts onto one explicit order and documented the conventions. I also built the handling for alert areas that cross the 180° line of longitude, which have to be split into separate shapes, one either side. Rolled out behind a feature flag and now live.
  • Alerts that follow the right phone. Location history is now kept per device and deleted after seven days, so someone signed in on several phones no longer gets alerts jumping between unrelated places. Rolled out behind a feature flag and now live.
  • One feature-flag system for every app. Features are switched on and off, and settings changed, in one place: Azure App Configuration. The backend reads it directly, and a single endpoint gives each app, the public app and the portal alike, its own flags and settings and the oldest app version still supported. A feature can roll out across the backend and the apps at once, without releasing a new app.
  • Tighter access. Stricter checks on who can do what, fixed checks on admin roles, and less personal data returned when reports are read.
  • Contract tests in CI. Tests that send real HTTP requests to the partner endpoints through the whole server, from the login and permission checks to input validation, against a temporary database. I found they weren’t running in CI at all, and some were failing without anyone knowing. I fixed them and made every pull request and release wait for them to pass.
  • AI-assisted development for the team. A shared repository of AI workflows. The Claude Code workflows are a private plugin that teammates install from it, a script copies matching Cursor rules into each project, and a check flags any workflow that exists on one side but not the other.

Architecture

The backend is a NestJS service running in a container on Azure App Service, with a MySQL database and Redis, all set up in Terraform. The public app and the app.ocean.org portal sign people in through Auth0; partners use API keys. Alerts go onto a Redis queue and out from there as push notifications, SMS and email.

Whale Report architectureThe Whale Report app and the app.ocean.org portal call the backend with Auth0 tokens, and partners call the version 2 partner API with API keys. Guards are declared route by route and check the token or key, roles and permissions. Behind them are the app routes for reports, alerts and accounts, and the partner API with its sharing scopes, expiry and cursor paging; both read and write MySQL through Prisma and feed the alert pipeline. The backend is a NestJS service on Azure App Service, and the alert pipeline of BullMQ queues on Redis sends push notifications, SMS and email to mariners. The partner OpenAPI specification is generated from the code and mirrored to apidocs.ocean.org when it changes.Whale Report appExpo · Auth0 tokenPortal · app.ocean.orgNext.js · Auth0 tokenPartnersAPI key · /v2/partnersPer-route guardsAuth0 token or API key · roles · permissionsApp routesreports · alerts · accountsPartner API v2scopes · expiry · cursorsAlert pipelineBullMQ queues on RedisPrismaMySQL Flexible ServerAzure App Service · NestJSOpenAPI specgenerated from the codeapidocs.ocean.orgmirrored when it changesPush · SMS · emailNotification Hubs and moreMarinersreal-time whale alerts
Three kinds of caller, one backend. Each route declares the check it needs on the caller's token or key and its permissions. The partner API's specification is generated from the code and copied to the docs when it changes.

The hard part

How long a grouped sighting should live

A hydrophone buoy hears the same whale at 12:00, 12:30 and 13:00, and each report says it’s relevant for one hour. The three reports are grouped into one sighting, which should stay visible until 14:00, an hour after the last one. Instead it disappeared at 13:00, while the two later reports were still current.

The code gave the group the shortest lifetime of its reports. That rule had been copied from sharing levels, where taking the most restricted is right. For a lifetime it’s backwards: a group should last as long as its most recent report, so it should take the longest.

Making only that change did nothing. Each report’s expiry was counted from when the sighting started, not from when the report came in, so every one-hour report expired at 13:00, and the longest of three identical times is still 13:00. Expiry had to be counted from each report’s own time. A report with no lifetime means “never expires”, so such a report now keeps its group visible; we confirmed that was intended before building it.

Making groups last longer broke an assumption nobody had written down: that any report inside a visible sighting is itself still current. Now an expired report could sit inside a visible sighting and still have its details shown. So every query that pulls in reports got the expiry check too.

Code review caught one more case. Extending a sighting’s lifetime was bundled into the same database write as the sharing-level check, and that write only goes through when the check passes. So when a new report would have opened up the sighting’s sharing level, which the rule rightly blocks, its lifetime wasn’t extended either, and nothing said so. Giving the lifetime its own write fixed it. Every earlier test had used a single sharing level, which is why nobody had seen it; the new test mixes two.

A second phase applied the same lifetime to alerts and their notifications, which had no expiry of their own until then.

Outcome

  • Partner API V2 is live and documented. Its specification comes from the code, and its endpoints are tested end to end on every pull request and release.
  • Sightings, alerts and notifications now expire on the same schedule, so a whale that keeps being heard keeps being reported.
  • Stricter checks on who can do what, including admins, and less personal data in report reads.
  • 460 merged pull requests as lead on the backend, 559 across Ocean Wise, and a shared AI workflow for the whole team.

Tell me what you're building