Skip to content

How to design a calendar (frontend)

The first sections are free. The deep dives, level expectations and quiz are part of Pro.

On this page
Asked at
Practice this question

The problem

A web calendar: day, week and month views over events that may repeat without an end date, that several people can edit, and that are read from whatever time zone the viewer is in. The answer turns on one fact: a repeating event may have no last occurrence, so the client keeps the rule and works out occurrences for the dates on screen, and the rest of the design (fetching by range, laying out a crowded day, showing an edit before the server answers) follows from treating the visible range as the unit of work.

Clarifying questions

AskWhy it mattersA typical answer

Does the server send repeating events as rules, or already worked out into occurrences?

It decides whether the client needs a rule expander and an exceptions map, or just a list of events per range. Most of the repeating-events discussion depends on this.

Rules. GET /events returns plain events, series (each with its rule) and exceptions, plus a sync token. The client expands the rules for the range it shows.

How busy is a calendar at the top end?

It sizes the day layout, the month view and the expansion of a repeating event, and tells you which of those is the first to hurt.

Say 50 events in a busy day, 1,000 in a heavy month with several shared calendars on, and a daily event that repeats 36,500 times over 100 years.

Can two people edit the same event at the same time?

Shared calendars make a conflict possible, which decides whether an edit carries a version and what the person sees when the server refuses it.

Yes. Shared calendars are in scope, so a PATCH carries the version the client last saw and the server may refuse it.

Which time zones matter: the viewer's, the event's, or both?

A series that keeps its local time across daylight saving changes has to be expanded in its own zone, and the viewer's zone is applied afterwards. If the answer is one zone, that work goes away.

Both. Each event carries its zone, and the viewer may be somewhere else; each event must show at the right local time for the viewer, across daylight saving changes.

Does it have to work offline?

Offline means a local store of record, a queue of edits and a reconciliation step, which is a different question.

No. Working offline is out of scope, as are reminders, room booking and finding a free time for a group.

Who uses it, and with what input?

Keyboard and screen reader support change the markup of the grid from the first step, rather than being added at the end.

Anyone. The grid must work by keyboard and with a screen reader, and a click or a drag must answer within 200 milliseconds.

Which views, and which is the widest?

The widest view bounds how many occurrences a rule is expanded into and how large a fetched range gets.

Day, week and month, and the person moves between them. Month is the widest, so a range is a month at most.

The requirements menu

RequirementScopeWhy

Show a day, a week and a month, and move between them

Core

The three views are the product. Moving between them is where a range cache earns its place.

Create, edit and delete an event, by a form or by dragging on the grid

Core

Dragging on the grid is what makes the response-time target bite, and the form is where repeat rules and guests are set.

Repeat an event, and edit one occurrence, it and the ones after it, or the whole series

Core

The hardest part of the data model and the thing most likely to be probed. The three edit scopes each change something different.

Invite people to an event and show their replies

Core

Invitations bring other people's edits into the picture, which is why edits carry a version.

Show several calendars at once, each in its own colour, each shown or hidden

Core

Several calendars on at once is what turns a month into a thousand events, and hiding one must not refetch anything.

Drag the edge of an event to change its length

Optional

Take it if the drag path is already built: resizing reuses the same snap, transform and version logic. Leave it if dragging to move is not finished yet.

Show a line for the current time on the day and week views

Optional

Cheap and useful, and it raises a small question about a timer that redraws without re-laying out the events. Take it late in the round if there is time.

Show a second time zone beside the hour labels

Optional

Take it if the interviewer asks about travel: it is the visible half of keeping each event's zone, and it costs one more column of labels. Leave it otherwise.

Push other people's changes to the open calendar as they happen

Optional

Take it only if asked. A calendar changes a handful of times in a day, so a sync token asked on an interval or on focus covers most of it with far less machinery than a connection held open per tab.

Search events by title

Optional

Useful but separate: it needs a server call over all dates, not the range on screen, so it does not share the fetching model. Mention it and move on.

Booking meeting rooms

Out of scope

A room is a resource with its own availability and its own conflicts, which is a scheduling question rather than a calendar view question.

Finding a free time for many people

Out of scope

Needs other people's busy times merged and searched, which is a backend computation with its own screen.

Reminders sent by email or text

Out of scope

Delivery outside the browser belongs to a notification service, not the web client.

Working offline

Out of scope

Would make the local store the record of truth and add a sync engine with its own conflict rules; a full question on its own.

Non-functional requirements

RequirementWhat it forces

A busy day of 50 events draws without lag, and a drag runs at 60 frames a second

The day layout (sort, group, assign columns) runs once per change of the day's events and is cached, not once per frame. During a drag the moved card is translated with a transform on its own layer and the layout is not rerun until the drop. Each card is memoized so a change to one event does not redraw the other forty-nine.

A click or a drag answers within 200 milliseconds

An edit shows on the grid before the server replies: the store is updated at once, the request goes out with the event's version, and the change is reverted with a message if the server refuses. A new event gets a temporary id so it can be drawn and even edited before the server names it.

Every event shows at the right time in the viewer's time zone, across daylight saving changes

Times are kept as an instant plus the event's zone, not as a bare UTC string. A series is expanded in its own zone so a daily nine o'clock stays at nine o'clock after a daylight saving change, and each occurrence is converted to the viewer's zone afterwards. The day an event lands on is computed in the viewer's zone too, since the UTC date can differ from it.

The grid works by keyboard and with a screen reader

The calendar is marked up as a grid of rows and cells with the roles assistive technology expects, one tab stop with arrow keys moving between cells, a visible label for the grid, and an announcement when an event is moved or an edit is refused. Dragging has a keyboard equivalent: pick up, move in steps, drop.

Core entities

EntityWhat it holds

Calendar

One source of events, shown or hidden as a whole, drawn in its own color.

Event

A single event, or the head of a series when it carries a repeat rule.

Exception

One occurrence of a series that differs from what the rule would produce, or has been removed.

Invitation

One person asked to one event, and what they said.

Client state

What the page knows right now, kept in one place so views, layout and edits read the same data.

The API

EndpointNotes

GET /events?start&end&calendars&time_zone → { events, series, exceptions, sync_token }

The one read. The client asks for the widest range it will show, a month at most, and gets single events, series with their rules and exceptions, each series once. sync_token is kept and sent on the next call to receive what changed, deletions included, instead of the whole range again.

POST /events { calendar_id, title, start, end, time_zone, rule, guests } → event

Create, with an optional repeat rule and a guest list. The client draws the event under a temporary id as soon as the form is submitted and swaps in the server's id from the response.

PATCH /events/{id}?scope=this|following|all { changes, version } → event

Edit. For a series, scope says whether to write an exception for this occurrence, split the series at it, or change the rule for all. version is what the client last saw; if the event changed on the server since then, the request is refused and the client shows a choice.

DELETE /events/{id}?scope=this|following|all

Delete with the same three scopes: a canceled exception, a series that ends before this occurrence, or the whole series.

POST /events/{id}/reply { reply } → invitation

The viewer's answer to an invitation. Shown at once beside their name and reverted if refused, like any other edit.

The high-level design

eventsview and dateCalendar gridServerClient store

Step 1 of 5

A grid that asks the server for what it shows

Start with the smallest thing that draws a calendar: the grid knows its view and date, asks the server for events in that span, keeps the answer in a client store and draws it. It already shows the shape of the data flow, and it already has the problems the rest of the design answers: moving a week forward asks the server again for days it just had, a repeating event has to arrive as separate events, a crowded day draws cards on top of each other, and nothing changes on screen until the server replies.

visible rangedrop or formmissing spanPATCH withversion andscopenew value now,old copy keptevents, series,exceptionssync tokenupdates anddeletionsrefused orconflictin the viewer'szonemonthcached columnsfew titles and acountCalendar gridFetched rangesPending editsServerClient storeChanges since lastsyncRevert and offera choiceExpand rules inthe event's zoneDay layoutDay summariesArrow keys,Enter, Escape
The whole design

What breaks first

The deep dives

Events that repeat. Someone sets up a daily stand-up with no end date, and the next week drags a single occurrence to the afternoon. What does your client store, what does it send, and how does the following Tuesday's stand-up get drawn?

A concept that helps here: Client caching and normalized stores

Laying out a busy day. A Tuesday holds 50 meetings, many overlapping by a few minutes. How does the day view decide each one's width and left edge, and what happens to that work while one of them is being dragged?

A concept that helps here: Drag and drop, and keeping orderA concept that helps here: Accessible widgets

Editing an event and seeing it at once. Someone drags a meeting from 2 PM to 3 PM on a slow connection. What is on their screen during the wait, and what changes when the server answers that someone else edited the meeting first?

A concept that helps here: Optimistic updates and rollbackA concept that helps here: Conflict resolution on the client

A month with thousands of events. Someone turns on five busy shared calendars and the month on screen holds more than a thousand events. What does the page fetch, what does it draw, and what happens when they switch to a week inside that month?

A concept that helps here: List virtualizationA concept that helps here: Client caching and normalized stores

Concepts this guide uses

Sources

  1. Google Calendar API: Recurring events
  2. Google Calendar API: Calendars and events (instances and exceptions)
  3. Google Calendar API: Synchronize resources efficiently
  4. Google Calendar API: Get specific versions of resources (etags and If-Match)
  5. Nylas: How the Google Calendar API handles recurring events
  6. TabMail iOS pull request 569: keep the original end when a recurring series is split
  7. RFC 5545: Internet Calendaring and Scheduling Core Object Specification (iCalendar)
  8. icalendar.org: RFC 5545 section 3.8.5.3, Recurrence Rule
  9. techinterview.org: Design a mobile calendar, sync and recurrence
  10. Arghya Majumder (dev.to): Google Calendar, Day View
  11. Arghya Majumder (dev.to): Google Calendar day view HLD
  12. FullCalendar docs: lazyFetching
  13. FullCalendar docs: slotEventOverlap
  14. MDN: ARIA grid role
  15. web.dev: Web Vitals
  16. web.dev: Defining the Core Web Vitals metrics thresholds
  17. web.dev: Stick to compositor-only properties and manage layer count
  18. TanStack Query docs: Optimistic updates
Sign in to report a mistake