How it works
PrematchNotificationJob runs on a periodic schedule and looks for matches that are about to start.The flow
- The job queries the
fixturestable for matches starting within a configurable window (default: 30 minutes). - For each upcoming match, it queries
cricket-match-followsto find all users who have followed that match. - Before sending, it cross-checks the
cricket-prematch-notificationstable to see if this user has already been notified about this match. This prevents duplicate notifications if the job runs multiple times within the window. - If the user hasn’t been notified, it sends a standard alert push notification via APNs. This is a regular push, not a Live Activity update.
- After sending, the notification is recorded in
cricket-prematch-notificationsso it won’t be sent again.
This is a regular APNs push notification, not a Live Activity push. The Live Activity is only started when the match goes live and the user has the app open (or via push-to-start if supported). The prematch notification is just a heads-up alert.
Edge cases
Configurable window: The 30-minute default is configurable. For high-profile matches, this could be extended. The window is checked against the fixture’s scheduled start time from SportMonks. No-follow, no-notification: Users only receive prematch notifications for matches they have explicitly followed. There is no broadcast to all users.Key tables
| Table | Purpose |
|---|---|
fixtures | Source of match schedule and start times |
cricket-match-follows | Which users follow which matches |
cricket-prematch-notifications | Deduplication: tracks which notifications have been sent |
Key jobs
| Job | Purpose |
|---|---|
PrematchNotificationJob | Periodic check for upcoming matches, sends alert pushes |
Areas of improvement
Dedup key is per-match, not per-user. The
prematchNotificationStore.ts uses matchId as the sole key. Once markNotificationSent is called, all users are considered notified. If a user follows a match after the notification was already sent (but before the match starts), they will never receive a prematch notification. A per-user dedup key (matchId + userId) would allow late followers to be notified on subsequent ticks.No followers triggers a retry loop with no backoff. When
getFollowersForMatch returns an empty array (line 148-150), the job logs “skipping (will retry)” and continues without calling markNotificationSent. This means every subsequent tick (every 60 seconds) will re-query followers for that match until the window expires. For matches nobody follows, this is wasted DynamoDB read capacity for the full 30-minute window.TTL-based cleanup is generous. The
prematchNotificationStore.ts uses a 48-hour TTL. This is fine for correctness but means the table retains records well past their usefulness. Consider aligning the TTL closer to the prematch window (e.g., 2-4 hours) to reduce table size.