Skip to content

feat: implement heartbeat service for marketplace presence with exponential backoff#35

Merged
shubham3121 merged 3 commits intomainfrom
feat/heartbeat-webhooks
Jan 28, 2026
Merged

feat: implement heartbeat service for marketplace presence with exponential backoff#35
shubham3121 merged 3 commits intomainfrom
feat/heartbeat-webhooks

Conversation

@shubham3121
Copy link
Member

This pull request introduces a robust heartbeat manager to the backend, enabling Syft Space to periodically send presence heartbeats to registered SyftHub marketplaces. The heartbeat system includes adaptive backoff, jitter, failure handling, and multi-marketplace support. Additionally, configuration options and supporting API changes are introduced to facilitate this feature.

Heartbeat Manager Integration:

  • Added a new HeartbeatManager service that sends periodic heartbeats to all active marketplaces, featuring adaptive interval management, exponential backoff, jitter, and failure recovery. This service is integrated into the FastAPI application lifecycle and can be enabled or disabled via configuration. [1] [2] [3] [4]

Supporting API and Repository Changes:

  • Extended the SettingsRepository with a get_public_url method, allowing the heartbeat manager to retrieve the current public URL dynamically.
  • Updated the application settings (AppSettings) to include a heartbeat_enabled flag, allowing deployment-time control over the heartbeat feature.

SyftHub Client Enhancements:

  • Added a send_heartbeat method to SyftHubClient for posting heartbeat data to SyftHub, along with a corresponding HeartbeatResponse model for parsing responses. Also introduced a default TTL constant for heartbeat messages. [1] [2] [3]
  • Minor import adjustment to support new features.

Application Initialization and Lifecycle:

  • Registered the HeartbeatManager as part of the FastAPI app's startup and shutdown sequence, ensuring it starts after other core services and receives the current tenant ID. [1] [2]
  • Minor code organization improvements for logging configuration. [1] [2]

These changes collectively enable Syft Space to reliably advertise its presence to SyftHub marketplaces, improving connectivity, monitoring, and operational resilience.

- Add HeartbeatManager service for sending periodic heartbeats to SyftHub
- Implement adaptive interval algorithm (15s → 600s max, 2x backoff)
- Reset to aggressive retry (15s) on failure for quick recovery
- Use TTL = 3x interval to tolerate missed heartbeats
- Add 10-15% jitter using secrets.SystemRandom to prevent thundering herd
- Wait for proxy connection before starting heartbeat cycle
…lic URL

- Replace proxy service with settings repository in HeartbeatManager for public URL management.
- Introduce method to retrieve public URL from settings.
- Adjust heartbeat loop to wait for public URL instead of proxy connection.
- Implement logic to handle public URL removal and prune stale marketplace states.
@shubham3121 shubham3121 merged commit 384701a into main Jan 28, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant