Building a Personalized Streaming Calendar in Next.js

2026-12-03来源 dev.toEnglish

I recently added a streaming calendar to Galaxy Movies. On the surface, it looks like a simple month grid. Underneath, it was mostly a data-shaping problem.

Galaxy Movies already tracks arrivals and departures across major streaming services. The data powers the new-on-streaming pages, leaving pages, alerts, social posts, newsletters, embeds, and the monthly churn report. So when I started the calendar, the question wasn't "how do I render a calendar?" It was "how do I turn streaming data into a calendar people can scan without giving up?"

That constraint shaped almost every implementation detail.
The first rule: no upstream API calls from the page
Streaming data is expensive in two ways. Some of it costs actual API quota, and all of it costs latency.

The calendar page doesn't call TMDB, Watchmode, JustWatch, or any other upstream source during SSR. It reads the diffs the ingestion pipeline has already written to Redis. Since I run on Upstash's free tier, the number of Redis commands matters too. The page uses one batched MGET through getBatchedProviderChanges instead of fanning out key by key.

const batched = await getBatchedProviderChanges(providerKeys, { region, includeMonthly: false }) const events = buildStreamingCalendarEvents({ changes: batched.changes, monthlies: batched.monthlies, providers, today }) setSwrCache(res, 21600, 86400) 

A few details hide in those few lines.

includeMonthly: false is deliberate. The monthly accumulation payloads are much larger because they include everything that arrived or departed during the month. The first version of the calendar only needs forward-looking dated events, so it avoids paying for data it won't render.

The page then caches the SSR result at the CDN for six hours, with a day of stale-while-revalidate. Streaming dates don't need second-level freshness, and the underlying diffs update daily.

Model the event, not the source data

Each source row has its own quirks. Some rows are dated arrivals. Some are scheduled departures. Some are monthly movement records. Some titles have TMDB IDs attached, and some don't.

The calendar flattens that into one event shape:

interface StreamingCalendarEvent { kind: 'arriving' | 'leaving' date: string title: string tmdbId: number tmdbType: 'movie' | 'tv' season?: number | null providerKey: string } 

That interface is the contract for the whole page. The UI doesn't care whether the event came from a dated provider announcement, a Watchmode row, or a JustWatch merge. It only cares about the date, direction, title, provider, and whether the event points at a movie or a show.

The tmdbId requirement matters. If a title can't be matched back to the catalog, it doesn't get a calendar event. That cuts some real data, but it also cuts the worst noise. A calendar full of unclickable rows would look more complete while being less useful.

Cap the noise

The biggest product decision was not a rendering decision. It was deciding how much not to show.

The calendar has a 90-day horizon. That matches the point where streaming announcements are still useful planning data. Beyond that, license dates get increasingly speculative.

It also caps events per provider and per date:

export const CALENDAR_HORIZON_DAYS = 90 export const CALENDAR_PROVIDER_EVENT_LIMIT = 24 export const CALENDAR_DATE_EVENT_LIMIT = 20 

There are smaller caps inside the builder too. A single provider can only put a few rows on the same day before lower-priority rows drop out. When several providers pile onto the same date, the builder round-robins across providers by popularity instead of letting one service dominate the whole cell.

This is the kind of logic that never shows up in a screenshot, but it's the difference between a calendar and a database dump.

Personalization stays client-side

Galaxy Movies already stores watchlist items and selected services in localStorage. That made it easier to personalize the calendar without turning it into an account-only feature.

The server renders the full regional event set. The browser then filters it with the user's local data:

const filteredEvents = events.filter((event) => { if (kindFilter !== 'all' && event.kind !== kindFilter) return false if (serviceFilterActive && !selectedServiceSet.has(event.providerKey)) return false if (watchlistOnly && !watchlistKeys.has(`${event.tmdbType}:${event.tmdbId}`)) return false return true }) 

There are three independent filters:

arrivals, departures, or both
selected services only
watchlist titles only

The nice part is that these compose. Someone can ask for only departures, only on their services, or only watchlist titles arriving anywhere tracked.

The hook uses useSyncExternalStore with a null server snapshot, so the server render matches hydration. After mount, the browser reads localStorage and the filters become personal. It avoids the classic SSR flash where the page first renders the wrong user state.

Posters are second-pass data

The calendar events don't carry poster paths. Adding them to every stored diff would duplicate data across providers and bloat every payload.

Instead, the page loads posters only for the selected day:

const items = [...missing.values()].slice(0, 50) fetch('/api/poster-paths', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ items }) }) 

The API caps batches at 50 items, caches poster lookups for a week, and rate-limits upstream fan-out. That means the initial calendar SSR stays small, while the day tray can still feel visual once opened.

This is a pattern I keep coming back to: keep the first render structural, then progressively add visual data only when the user asks for a narrower slice.

Date-only values need UTC discipline

Streaming release dates are date strings, not moments in time. 2026-12-18 doesn't mean midnight in the user's local timezone. It just means December 18.

So the calendar parses and formats dates as UTC:

function parseUtcDate(date: string): Date { const [year, month, day] = date.split('-').map(Number) return new Date(Date.UTC(year, month - 1, day)) } 

Without that, users behind UTC can see events shift into the previous day. It's a small bug that's easy to miss in local development and very visible in a calendar UI.

This mattered even more because Galaxy Movies runs on Cloudflare Workers in production. Server and client rendering need to agree exactly. Date formatting is one of the easiest ways to create a hydration mismatch when you stop being explicit about time zones.

Small UI decisions carried a lot of weight

A few interface choices mattered more than I expected.

The selected day opens inline inside the same week row instead of using a modal. That keeps the calendar spatial. You don't lose your place just because you wanted details.

Month navigation is intentionally bounded. You can move through the current month and the next three months, matching the 90-day data horizon instead of implying there's infinite future data.

Arrivals and departures use separate colors everywhere. Green means arriving; red means leaving. That sounds obvious, but the color has to survive the month cell, mobile count, day tray, and badges, or people have to relearn the visual language on every surface.

On desktop, day cells show a few title rows. On mobile, they collapse into a count. The details are one tap away, but the month grid doesn't become unreadable on a small screen.

What I learned

The calendar itself is not complex. A month grid is one of the oldest UI patterns on the web.

The useful part was everything around it:

  • read cached pipeline data instead of hitting upstream APIs
  • normalize source-specific rows into one event contract
  • cap noise before it reaches the UI
  • personalize as a view concern, not a data-ingestion concern
  • lazy-load poster metadata only for the selected slice
  • treat date-only values as UTC values everywhere
  • reuse the same implementation across regions

The biggest lesson was that data volume isn't the goal. Confidence is. A streaming calendar that shows everything is technically impressive for about five seconds; then it becomes homework. The better version shows fewer rows, but each row is more likely to mean something.

You can view the calendar here if you want to see how it came out.

原文:https://www.a8q9.cn/en/article/building-a-personalized-streaming-calendar-in-next-js-3b72e0.html

相关文章