Back to Projects

Work Orders

Java / Spring Boot

JavaSpring BootOAuth2Multi-tenant

Work Orders is a Spring Boot API. The caller is a JWT, and every query filters on the tenant_id claim. The repository has no finder that loads a work order by id alone, so another tenant's token gets a 404. Create, list, and update are validated. springdoc publishes the OpenAPI document. The process uses Java 21 virtual threads, and the HTTP server timer publishes a percentile histogram. No p95 figure is stated here, because none has been measured against a stated workload.

tenant_id
Isolation

Taken from the JWT. The request body cannot choose the tenant

The Problem

A multi-tenant API that accepts a tenant id from the request body will serve one tenant's rows to another tenant. A list that filters and a get-by-id that does not is the usual hole.

The Solution

The tenant comes from the token. Create, list, get, and update all pass that claim into Spring Data JPA methods that include the tenant. Get and update use findByIdAndTenantId.

Technical Decisions

Key architecture decisions and their outcomes

No query by id alone

Context

A get-by-id that ignores the tenant returns another tenant's work order to anyone who can guess the UUID.

Decision

WorkOrderRepository exposes findByTenantIdOrderByCreatedAtDesc and findByIdAndTenantId. The service takes the tenant from the JWT and does not call findById.

Outcome

A token for tenant B gets 404 for tenant A's work order, and an empty list.

Latency is a histogram, not a published number

Context

A p95 written into a README without a workload, a machine, and a run is a guess.

Decision

Virtual threads are on. management.metrics.distribution.percentiles-histogram.http.server.requests is on. The README says to read /actuator/metrics/http.server.requests after sending traffic.

Outcome

The timer is there. This page does not claim a percentile.

Engineering Details

  • The demo RSA public key is committed so the tests and a local caller can mint tokens. The README says to replace it before the API is exposed
  • Hibernate ddl-auto is validate. Flyway owns the schema
  • POST, GET, and PATCH /api/work-orders
  • Testcontainers Postgres. The test signs a JWT with the demo private key

Key Highlights

  • OAuth2 resource server with a tenant_id claim
  • Spring Data JPA queries always include the tenant
  • Another tenant receives 404, including on update
  • Bean Validation and a springdoc OpenAPI document
  • Virtual threads enabled, with a histogram on http.server.requests
  • Tests mint a JWT and prove the tenant boundary

Tech Stack

Skills & Technologies

Related Projects