Scrivio Interview library

REST API design with Spring

41 questions in 10 subtopics.

Resource modelling

ConceptFoundations6 min read
What is ProblemDetail in Spring Framework 6 and how does it relate to error responses in a REST API?
ConceptFoundations6 min read
You are designing endpoints for an order system in Spring MVC. A colleague proposes POST /createOrder, GET /getOrder?id=5 and POST /cancelOrder?id=5. How would you model these as REST resources, and which HTTP methods and status codes would you use?
CodingFoundations6 min read
Write a Spring MVC controller method that creates a customer from a JSON body, validates it, and returns 201 with a Location header. What annotations and return type do you use?
ScenarioIntermediate7 min read
A mobile team complains that rendering one screen needs seven calls to your REST API (user, orders, addresses, and so on). How do you decide between adding an aggregate endpoint, supporting field selection or embedding, introducing a backend-for-frontend, or moving to GraphQL?
DesignIntermediate6 min read
Design the REST resources for a bank transfer between two accounts, including how a client learns the transfer's outcome when processing takes several seconds. Where would you use synchronous responses and where asynchronous ones?
LeadershipAdvanced5 min read
You lead API standards for 40 teams whose REST APIs differ in naming, error formats and pagination. What would you put in a company API guideline, and how would you get adoption without blocking delivery?
LeadershipPrincipal5 min read
Over ten years your company built several hundred internal REST APIs with inconsistent models of the same business concepts (customer, account, product). What long-term strategy would you set for the shape of those APIs and the data concepts behind them?

Versioning

ConceptFoundations6 min read
What are the common ways to version a REST API (URI path, header, query parameter, media type), and what are the practical differences between them?
CodingIntermediate6 min read
In Spring Framework 7 and Spring Boot 4 you need GET /accounts/{id} to serve two response shapes depending on an API-Version request header. How can you implement this with the framework's versioning support, and how would you do it on an older Spring version?
DesignAdvanced5 min read
Define a versioning and deprecation policy for public and internal REST APIs across a company of many teams. What counts as a breaking change, how long do old versions live, and how is retirement enforced?
LeadershipPrincipal6 min read
Your company supports five major versions of its public API, and each new feature must be back-ported to several of them. Engineering cost keeps rising. How would you change versioning strategy for the next five years?

Pagination and sorting

CodingFoundations6 min read
A Spring MVC endpoint returns Page<ProductDto> directly from a controller using Spring Data's Pageable argument. What does the JSON look like, what problems can that cause, and what does newer Spring Data recommend?
DebuggingIntermediate6 min read
Users report that paging through a list of orders sorted by status sometimes shows the same order on two pages and skips others. The query is ORDER BY status LIMIT 20 OFFSET :offset. What is the cause and the fix?
DesignIntermediate6 min read
An endpoint GET /events?page=5000&size=50 on a table with 200 million rows has become slow. Explain why offset pagination degrades and design a keyset (cursor) pagination API in Spring, including the SQL and the cursor format.
DesignAdvanced5 min read
Set a company standard for pagination, filtering and sorting in REST APIs used by web, mobile and partner clients. What would the standard specify and why?
LeadershipPrincipal6 min read
Ten years ago your platform's public API exposed offset pagination with exact total counts on every list endpoint. Now the counts dominate database load. How do you reason about the cost of that early decision and what do you do now?

Idempotency

ConceptFoundations5 min read
Which HTTP methods are idempotent by definition, and why does idempotency matter for a client that retries after a timeout?
DesignIntermediate7 min read
Design idempotent POST /payments in a Spring Boot service using an Idempotency-Key header. Cover storage, concurrent duplicates, what is returned on replay, and expiry.
ScenarioAdvanced5 min read
Several teams retry calls between services with different policies, and a recent incident created duplicate shipments because the shipping service treats every POST as new. What cross-team standard would you set for idempotency?
LeadershipPrincipal5 min read
How would you argue for investment in end-to-end idempotency (APIs, messaging, payments) to leadership that sees it as engineering overhead?

HATEOAS

ConceptFoundations6 min read
What is HATEOAS, and how does Spring HATEOAS help you add links to a response for GET /orders/{id}?
ScenarioIntermediate5 min read
Your team debates adopting HATEOAS for an internal API consumed by three known services. Most client code hardcodes URLs anyway. What would you recommend and why?
DesignAdvanced6 min read
A partner-facing workflow API (application submitted, under review, approved, rejected) changes its allowed transitions every quarter. How could hypermedia controls reduce the coordination cost with partners, and what would you need in place for it to work?
LeadershipPrincipal5 min read
HATEOAS has been recommended for two decades but few public APIs use it fully. What does that history tell you when evaluating architectural ideals for your organisation's API strategy?

OpenAPI and springdoc

ConceptFoundations6 min read
How does springdoc-openapi generate an OpenAPI document from a Spring Boot application, and how do you improve the generated description of an endpoint?
ScenarioIntermediate6 min read
Your team must choose between code-first (springdoc generates the spec from controllers) and design-first (write OpenAPI YAML, generate server interfaces with openapi-generator). What are the trade-offs and what would you pick for a partner API?
DesignAdvanced6 min read
How would you build an API catalog and governance process based on OpenAPI documents for 200 services, so that consumers can find APIs and breaking changes are caught before release?
LeadershipPrincipal7 min read
You are deciding whether machine-readable API contracts (OpenAPI, AsyncAPI, protobuf) should be mandatory for every service in the company. What long-term benefits and costs would you weigh?

Backward compatibility

ConceptFoundations7 min read
Which of these changes to a JSON response are backward compatible for existing clients: adding a field, renaming a field, changing a number to a string, adding a new enum value, making an optional request field required?
ScenarioIntermediate7 min read
You need to split the field name into firstName and lastName in a widely used customer API without a new major version. Describe the steps and how long each phase lasts.
DesignAdvanced7 min read
How do you design for backward compatibility across many services that deploy independently, so that rolling deploys and mixed versions never break calls between them?
LeadershipPrincipal6 min read
What organisational practices determine whether an engineering organisation can keep APIs compatible for many years, beyond the technical techniques?

REST vs SOAP

ConceptFoundations7 min read
Compare REST over HTTP with JSON and SOAP web services: contract, message format, error handling, tooling and security standards. When would you still choose SOAP today?
ScenarioIntermediate7 min read
A Spring Boot service must call a partner's SOAP API that uses WS-Security signatures, while exposing a REST API to your own clients. How would you structure the integration and test it?
LeadershipPrincipal6 min read
Your company still runs 70 SOAP services built 15 years ago, used by partners and internal systems. Should you rewrite them as REST? How do you decide and plan over several years?

Long-running operations

DesignFoundations7 min read
A POST /reports request takes 5 to 20 minutes to generate a report. Design the API so clients do not hold an HTTP connection that long.
CodingIntermediate7 min read
Implement the long-running job pattern in Spring Boot: POST starts the work asynchronously and returns 202, GET returns status, and jobs survive a pod restart. What components do you use?
DesignAdvanced7 min read
Define a platform standard for asynchronous and long-running operations across 50 teams' REST APIs, covering status resources, callbacks and failure semantics.

OpenAPI code generation

CodingFoundations6 min read
Configure the OpenAPI Generator Maven plugin to generate Spring server interfaces from an orders.yaml spec, and explain how you implement the generated interface without editing generated code.
ScenarioIntermediate7 min read
Clients generated from your OpenAPI spec in Java, TypeScript and Kotlin keep breaking: enum additions crash old clients, nullable fields are typed wrongly and model names change between generator versions. How do you make code generation reliable?
LeadershipAdvanced5 min read
Should your organisation generate server stubs from OpenAPI (design-first) for all teams, or let teams generate the spec from code? Lay out how you would decide and roll it out.