Notifications
The platform is designed to alert users within seconds of a critical event (e.g., Horse Cast).
Channels
-
In-App (Bell Icon)
- Persistence: Saved in database (
notificationstable). - Real-Time: Delivered via Websocket (
camera:alertevent). - Service:
NotificationService.
- Persistence: Saved in database (
-
Email
- Provider: SMTP (Configurable via
.env). - Usage: Weekly reports, Critical Alerts (if configured).
- Provider: SMTP (Configurable via
-
SMS
- Provider: Twilio.
- Usage: Critical Alerts ONLY (High cost, user must opt-in).
-
Mobile Push
- Provider: Expo Push API / Google FCM.
- Service:
ExpoServerSdk.
Real-Time Architecture
The system uses a robust Pub/Sub architecture to ensure reliable notification delivery across distributed instances and during restarts.
Components
-
Socket.IO Rooms:
- Users subscribe to a dedicated "Room" upon connection:
socket.join('user_{userId}'). - This replaces manual socket tracking and eliminates memory leaks.
- Users subscribe to a dedicated "Room" upon connection:
-
Redis Adapter:
- Serves as the communication bus between backend instances.
- When an API node emits a notification, it publishes to Redis.
- All API nodes receive the message and forward it to their connected clients participating in the target Room.
Event Flow
Resilience & Auto-Healing
The system is designed to handle server restarts transparently:
- Server Restart: Connections drop, backend memory (Rooms) is cleared.
- Client Reconnection: Frontend
socket.io-clientautomatically attempts reconnection (backoff strategy). - Resubscription: Upon
connectevent, the frontend immediately re-emitssubscribeToNotifications. - Recovery: The new socket joins the
user_{id}room, and real-time alerts resume instantly.