Design an API that exposes the ad-assignment function as a production service.
The service receives a user, a list of browser positions, and a set of candidate ads. It should randomly assign eligible ads to positions while respecting each ad's per-user display limit. The service must also persist and update per-user ad display state.
Discuss the following:
-
What API endpoint or endpoints would you expose?
-
Would you use REST, RPC, or another protocol? Why?
-
Which HTTP method should be used for generating an assignment?
-
What should the URL design look like?
-
What should the request and response schemas contain?
-
Where should per-user ad display state be stored?
-
How would you update state safely when there are concurrent requests for the same user?
-
What errors should the API expose to clients?
-
How would you make the API reliable, observable, and maintainable?