Introducing a new way to review your PRs.

Read the announcement

hcavarsan / pipedash

One dashboard for CI/CD pipelines across multiple providers

View on GitHub

19 documents · Updated Nov 23, 2026

docs / push-relay-service

Push relay service

The push relay service is a small standalone gateway that stores mobile push registrations and delivers notifications to Apple Push Notification service (APNs). The main Pipedash server sends a relay subscription ID and notification data to this service, so the relay can keep APNs credentials and device tokens outside the main application.

The relay is a child service of Event delivery and notifications. Its stored registrations and client-facing notification behavior are described with the client notifications page.

Service role

Delivery boundary

The relay separates notification delivery from the main Pipedash server. A mobile client registers its APNs token with the relay, while the Pipedash server later uses the returned subscription ID to request delivery.

The relay owns the APNs-specific work. It selects the APNs environment, signs requests with the configured Apple key, builds the alert payload, and turns APNs results into a small set of HTTP outcomes.

The following diagram shows the normal delivery path.

flowchart LR
    Client[Mobile client] -->|register token| Relay[Push relay]
    Relay -->|subscription ID| Server[Pipedash server]
    Server -->|notification + subscription ID| Relay
    Relay -->|APNs request| APNs[Apple Push Notification service]
    APNs -->|delivery result| Relay
    Relay -->|accepted, gone, or failure| Server

References: crates/…/main.rs• L80-116 crates/…/routes.rs• L103-114 crates/…/push.rs• L213-253

Deployment boundary

The service runs as its own binary and can run in the supplied container image. The image listens on port 8080, stores its SQLite database under /data, and runs as a non-root user. The /data volume is therefore part of the service's durable state.

References: crates/…/Cargo.toml• L1-13 docker/push-relay.Dockerfile• L42-56

Configuration

Runtime settings

The relay reads its settings from environment variables when it starts. It fails to start when the APNs identity or allowed application bundle list is missing, because these values define who may use the relay and which Apple account signs requests.

SettingPurposeDefault or requirement
RELAY_BIND_ADDRNetwork address for the HTTP service0.0.0.0:8080
RELAY_DATABASE_PATHSQLite database locationpipedash-push-relay.db
RELAY_APNS_KEYAPNs private key contentUse this or RELAY_APNS_KEY_PATH
RELAY_APNS_KEY_PATHFile containing the APNs private keyRequired when the key is not inline
RELAY_APNS_KEY_IDApple key IDRequired
RELAY_APNS_TEAM_IDApple team IDRequired
RELAY_ALLOWED_BUNDLE_IDSComma-separated application bundle IDsRequired and must contain at least one ID
RELAY_TRUSTED_PROXYAllows client identity from X-Forwarded-ForDisabled unless set to true or 1

The allowed bundle list is checked during registration. The trusted proxy switch changes only how the relay identifies a client for registration limits, so it must match the network path that fronts the service.

References: crates/…/config.rs• L7-69

APNs credentials

The relay expects an APNs ES256 private key in PEM form, plus its key ID and team ID. It creates a signed provider token and reuses that token for less than an hour. An APNs response that says the provider token expired causes the relay to create a fresh token for later requests.

References: crates/…/config.rs• L41-68 crates/…/apns.rs• L58-121 crates/…/apns.rs• L314-335

HTTP interface

Health route

GET /healthz returns ok without reading or changing subscriptions. It is suitable for a process or load-balancer health check.

References: crates/…/routes.rs• L103-114 crates/…/routes.rs• L227-229

Subscription routes

Subscription routes create and maintain the relay's link to one device. A successful registration returns a random subscription ID. The relay stores only a hash of that ID, which lets the ID act as a secret lookup value without placing the value itself in the database.

RouteResponsibilityMain result
POST /v1/subscriptionsRegister a device token, APNs environment, and bundle ID201 with subscription_id
PUT /v1/subscriptions/{subscription_id}Replace a rotated device token204
DELETE /v1/subscriptions/{subscription_id}Remove a registration204

The relay accepts only valid hexadecimal device tokens, the production or sandbox environment, and bundle IDs from its allow-list. It keeps at most ten registrations for one device token, so newer registrations displace the oldest ones.

References: crates/…/routes.rs• L152-199 crates/…/routes.rs• L231-294 crates/…/store.rs• L40-55 crates/…/store.rs• L80-114

Notification route

POST /v1/notifications accepts a subscription ID and one alert description. It first resolves the subscription, then sends the alert to APNs using the stored device token, environment, and bundle ID. A successful APNs request returns 202 Accepted.

The request supports two notification forms:

  • A title and body, with optional thread and pipeline details. Pipeline details add a destination that the client can use to open the related run.
  • An alert_id for the newer generic alert form. This form carries the alert ID to the client and supports APNs collapse and expiry behavior.

The relay rejects mixed forms and oversized request fields before it contacts APNs. The total request body limit is 16 KiB.

References: crates/…/routes.rs• L60-71 crates/…/routes.rs• L164-179 crates/…/routes.rs• L296-375 crates/…/apns.rs• L139-241

Rate limiting

Request windows

The relay uses separate fixed windows for registration and delivery. Registration limits protect the public token-registration surface, while delivery limits apply independently to each subscription so one busy device does not block other devices.

OperationLimitKey
Registration20 requests per hourClient IP, or forwarded client IP when a trusted proxy is enabled
Notification30 requests per minuteHashed subscription lookup key

An IPv6 client is grouped by its /64 prefix. When proxy trust is disabled, forwarded headers do not change the client identity. Requests over a window receive 429 Too Many Requests.

References: crates/…/routes.rs• L67-71 crates/…/routes.rs• L202-225 crates/…/routes.rs• L231-238 crates/…/routes.rs• L343-354

Limiter cleanup

Rate-limit state is kept in memory and is removed after its window ends. A background sweep runs every five minutes to discard inactive keys, so the limiter does not grow with every client that has ever connected.

References: crates/…/rate_limit.rs• L16-66 crates/…/main.rs• L30 crates/…/main.rs• L70-77

Persistence

Subscription records

The relay uses SQLite as its durable store. Each record contains the hashed subscription ID, device token, APNs environment, bundle ID, creation time, and last activity time. Database migrations run when the service opens the database.

The store uses write-ahead logging and a short busy timeout. This supports the small concurrent workload of registration, token rotation, delivery, and cleanup without turning the relay into a separate database service.

References: crates/…/store.rs• L40-77 crates/…/20261024000001_subscriptions.sql• L1-11

Subscription lifetime

Token rotation and successful delivery update the last activity time. A background task removes registrations that have been inactive for 90 days, and it checks for expired records once per hour. A failed APNs request does not refresh or remove a registration because a temporary provider or network error does not prove that the device token is invalid.

References: crates/…/main.rs• L28-29 crates/…/main.rs• L55-67 crates/…/store.rs• L137-180 crates/…/routes.rs• L355-374

APNs delivery

Environment routing

Each subscription records whether its token belongs to the production or sandbox APNs environment. The relay sends the request to the matching Apple host and uses the registered bundle ID as the APNs topic.

The relay sends alert pushes over HTTP/2 with a short connection timeout and request timeout. It signs each request with a bearer provider token and sets alert priority and push type headers.

References: crates/…/apns.rs• L31-37 crates/…/apns.rs• L262-305

Delivery outcomes

The relay maps APNs results to subscription state and HTTP responses. This keeps token cleanup tied to an explicit invalid-token result instead of removing registrations for every provider error.

APNs resultRelay actionHTTP result
AcceptedTouch the subscription's activity time202 Accepted
Unregistered or bad device tokenDelete the record only if its token is still unchanged410 Gone
Network error or other APNs rejectionKeep the record for a later attempt502 Bad Gateway

The token comparison matters when a device rotates its token while an older notification is still in flight. The older failure must not delete the newer token.

References: crates/…/apns.rs• L124-136 crates/…/routes.rs• L355-374 crates/…/store.rs• L162-180

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep the relay request fields aligned with the Pipedash server's relay client and with the mobile payload fields.
  • Keep allowed bundle IDs aligned with the APNs topic and the app builds that register device tokens.
  • Preserve the same subscription-ID hashing rule for every create, lookup, rotate, delete, and notification path.
  • If rate-limit keys or proxy handling change, review the edge proxy configuration because client grouping can change without an API change.
  • If subscription cleanup or token error handling changes, verify that a rotated token cannot be removed by an older in-flight APNs result.

Important failure modes

TriggerConsequenceGuard
Missing APNs key, key ID, team ID, or bundle allow-listThe relay does not startStartup configuration validation
Invalid or unapproved device registrationNo subscription is createdToken validation and bundle allow-list check
Registration burst from one clientRegistration receives 429Per-client hourly window
More than 30 notifications for one subscription in one minuteNotification receives 429Per-subscription delivery window
APNs reports an unregistered tokenThe matching subscription is removed and the caller receives 410Delete only when the stored token still matches
APNs is unavailable or rejects another requestThe subscription remains and the caller receives 502Failure classification keeps the record
Database path is not persistent in deploymentRegistrations disappear after restartMount the relay data volume

Key files

FileWhy to read it
crates/…/main.rsService startup, background cleanup, listener, and shutdown
crates/…/config.rsRuntime settings and required APNs configuration
crates/…/routes.rsHTTP routes, request contracts, validation, and response outcomes
crates/…/store.rsSubscription state and lifecycle rules
crates/…/apns.rsAPNs signing, payloads, environment routing, and result mapping
crates/…/rate_limit.rsFixed-window rate-limit behavior
crates/…/20261024000001_subscriptions.sqlDurable subscription schema
docker/push-relay.DockerfileContainer defaults, port, user, and data volume
crates/…/push.rsMain-server calls into the relay and handling of relay outcomes