Skip to content

perf(SF2.0): Stream predictions to UpcomingDepartures.Server instead of polling#3247

Merged
joshlarson merged 46 commits into
mainfrom
jdl/feat/upcoming-departures-predictions-streaming
Jun 10, 2026
Merged

perf(SF2.0): Stream predictions to UpcomingDepartures.Server instead of polling#3247
joshlarson merged 46 commits into
mainfrom
jdl/feat/upcoming-departures-predictions-streaming

Conversation

@joshlarson

@joshlarson joshlarson commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

Scope

Asana Ticket: 📅🔎🎭 Extract prediction fetching out of Upcoming Departures GenServer

Implementation

(Don't bother looking at this commit-by-commit - the commits are kind of a mess - sorry!)

Dotcom.Predictions

This introduces a new namespace with the following modules:

  • Dotcom.Predictions.Manager
    • The entrypoint to the outside world - consumers can call subscribe or unsubscribe in order to receive messages when predictions data is added or modified. When a process subscribes to a predictions stream, it creates an EventSupervisor that (see below) gathers up predictions events and sends them back to its subscribers.
  • Dotcom.Predictions.EventSupervisor
    • A supervisor that supervises two children - a ServerSentEventStage that hooks into the V3 API to get 🥟steamed🥟 messages, and an EventBroadcaster.
  • Dotcom.Predictions.EventBroadcaster
    • A simple worker set up to receive events from the server sent events stream and broadcast them back to the Manager.

Other Changes

There are other oddball changes in this PR:

  • Dotcom.UpcomingDepartures.Server
    • Re-architect this module a decent amount in order to handle messages from the predictions stream, rather than polling @predictions_repo.
  • DotcomWeb.Live.UpcomingDeparturesLive
    • Update to handle a :loading? state from UpcomingDepartures.Server.
  • PredictedSchedule.Collection
    • Add some more convenience functions to make it respond nicely to the types of prediction update events that we get from the API.
  • Predictions.StreamParser
    • Its original implementation dropped timezone information; this PR updates it to work the same as Predictions.Parser.

Screenshots

Screenshot 2026-06-10 at 1 48 08 PM

Enjoy this side-by-side of local and prod for Green Line at Fenway Westbound, on either side of a photo of a Green Line train at Fenway going Westbound.

You may notice that local has one timestamp different from prod - that's because by virtue of streaming, this branch responds more quickly to updates than prod does, hence local showing a lower number of minutes remaining than prod (prod updated to also show 17 about 3 seconds after I took ☝️ screenshot).

How to test

Visit any departures page and verify that it loads upcoming departures as expected.

You won't notice much in the way of visual changes, but you might notice that this branch responds to changes in a snappier way.

@joshlarson joshlarson added the dev-green Deploy to dev-green label Jun 10, 2026
@joshlarson joshlarson added dev-blue Deploy to dev-blue and removed dev-green Deploy to dev-green labels Jun 10, 2026
@joshlarson joshlarson marked this pull request as ready for review June 10, 2026 21:43
@joshlarson joshlarson requested a review from a team as a code owner June 10, 2026 21:43
@joshlarson joshlarson requested a review from thecristen June 10, 2026 21:43

@thecristen thecristen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm feeling good about this and all the different bugs we've tackled on it today. I'd like to give this a whirl.

@joshlarson joshlarson mentioned this pull request Jun 10, 2026
@joshlarson joshlarson enabled auto-merge (squash) June 10, 2026 23:02
@joshlarson joshlarson merged commit 03bc1d9 into main Jun 10, 2026
16 of 17 checks passed
@joshlarson joshlarson deleted the jdl/feat/upcoming-departures-predictions-streaming branch June 10, 2026 23:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dev-blue Deploy to dev-blue

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants