31. Design an API for scheduling and managing calendar events.
Define APIs for event creation, recurrence, attendee responses, free-busy lookup, updates, cancellation, pagination, authorization, and versioning.
At a high level, I would expose one versioned calendar API over HTTPS. The client signs in through OAuth2, receives a JWT, and sends it as a Bearer token. The API layer validates the token before routing requests. The API supports creating, updating, cancelling, listing, free-busy lookup, and attendee responses. Separate services own events, recurrence, RSVP data, availability, and notifications. Free-busy uses a cache with a fallback data source. Notifications run asynchronously. This adds operational work, but it keeps ownership clear and the main API path responsive.
The goal is to provide one secure API for scheduling and managing calendar events. The main challenge is separating event logic, security, availability, and notifications. I would explain the design by following the request from the client to each service.
- Which clients and core use cases must the API support?
- What authentication, authorization, and data-validation rules should I assume?
- What scale, error handling, idempotency, and versioning requirements matter?
I would start with the user signing in through the Auth or Identity Provider.
The design uses OAuth2 with the authorization code flow or PKCE. OAuth2 is a standard way to grant application access. The identity provider returns an access token in JWT form, with an ID token also shown.
JWT means JSON Web Token. It contains identity and permission claims. The User or Client App sends the JWT as a Bearer token with each HTTPS request.
The client is outside the trusted internal system. HTTPS protects the request and JSON payload while they travel over the network. The HTTPS JSON response returns from the API layer to the client.
The Calendar API Gateway or REST API is the system entry point. It receives the client request over HTTPS.
The Authorization and JWT Validation component checks the token. It verifies the signature, expiry, scopes, and claims. Authentication proves the caller's identity. Authorization checks whether that caller may perform the requested action.
The request continues only after a successful validation result. If validation fails, the request must stop before reaching a domain service. The diagram does not define a specific failure status code, so I would keep that response generic.
The API uses version /v1. Versioning allows future API changes without immediately breaking existing clients.
The API surface contains six visible routes.
POST /v1/events creates an event. The Event Service returns 201 with the created event.
PATCH /v1/events/{id} updates an event. The response returns 200 with the updated event.
DELETE /v1/events/{id} cancels an event. The response returns 200 with the cancelled event.
POST /v1/events/{id}/responses records an attendee response. The response returns 200 with the recorded RSVP.
GET /v1/free-busy requests availability. The Free-Busy Service returns 200 with the free-busy data.
GET /v1/events?pageToken=...&pageSize=... lists events in pages. The response contains the items and a nextPageToken.
Recurrence is handled as part of event creation or updates. The Recurrence Service expands and validates recurrence rules shown in the event flow.
The Event Service owns creating, updating, cancelling, and reading events. It reads and writes the Calendar DB or Event Store.
The Recurrence Service expands and validates recurrence rules. It reads and writes Recurrence Data.
The Attendee Response Service records and reads attendee responses. It stores them in Response Storage.
Each service receives a request from the API layer. It performs its owned operation and returns a separate response. This keeps request and response directions clear.
The benefit is focused ownership. A change to recurrence logic does not need to change attendee-response storage.
The Free-Busy Service computes availability for the requested users and time range.
It first reads the Availability Cache or Index. A cache stores commonly used data for faster access. On a cache hit, the data returns directly to the service.
If the cache misses, the service follows the shown fallback path. It reads the Event Data or Index backup source. The data result then returns to the Free-Busy Service and back through the API.
The benefit is lower response time for common lookups. The downside is that the cache and fallback source must remain coordinated.
Event changes can enqueue notification work. The Notification Worker processes jobs and sends reminders, updates, or cancellation messages.
The Job Queue or Outbound Notifier holds the work. Outbound Channels deliver messages through email, push, or SMS.
This work is asynchronous. The event API response does not wait for final message delivery. This keeps event operations responsive, but notification delivery may happen later.
The design sends audit logs, metrics, traces, and alerts to Audit Log, Monitoring, and Observability. These signals help the SRE team investigate errors and performance issues.
The main trade-off is operational complexity. Separate services, data stores, caching, and queued work require more deployment and monitoring. We accept this because the design keeps security checks, ownership, and scaling boundaries clear.
The benefit of this design is clear ownership. The Event Service owns normal event operations. Other services own recurrence, attendee responses, availability, and notifications. This makes each part easier to test and scale. The downside is that more services need more monitoring and deployment work. JWT validation protects every API call, but clients must obtain and send a valid token. Version /v1 protects current clients, but future versions may need parallel support. Pagination prevents very large event responses. The availability cache makes free-busy requests faster, but cache misses require the backup Event Data or Index. Asynchronous notifications keep the main API fast, but delivery happens later. We accept these costs because the design keeps the request path clear and separates important responsibilities.
Interviewers use this question to test engineering judgment, not endpoint memorization. They want clear API boundaries, correct HTTP methods, and correct request and response directions. They also check whether authentication and authorization are separated properly. Strong answers explain versioning, pagination, service ownership, caching, fallback behavior, asynchronous notifications, and observability. The candidate should explain why each choice helps and what operational cost it adds.








