Skip to content

feat(messaging): Appwrite user push without a device target - #13876

Merged
ArnabChatterjee20k merged 3 commits into
mainfrom
feat-mqtt-user-push-no-target
Sep 24, 2026
Merged

ArnabChatterjee20k merged 3 commits into
mainfrom
feat-mqtt-user-push-no-target

Conversation

@ArnabChatterjee20k

Copy link
Copy Markdown
Member

What

For the built-in Appwrite push provider, delivering a per-user notification no longer requires a device push target. A users: [userId] campaign now delivers straight to the user's reserved MQTT topic users/<userId> — the same topic the user subscribes to with just their session.

Follow-up to #13860 (reserved per-user topics), now merged.

Why

The Appwrite/MQTT provider delivers over the broker, where the MQTT subscription is the registration — there is no device token to store. Yet the old flow still forced developers to:

  1. account.createPushTarget(id, token) — with a required device token that this provider never reads, and
  2. rely on that target existing, or users: [userId] silently resolved to zero recipients (no error).

So a user could successfully subscribe to users/<their id> and still receive nothing unless a dummy target was registered first — a confusing, asymmetric DX.

What changed

  • Messaging worker (streamRecipients): when the push provider is appwrite, the users[] param addresses each user id directly (users/<userId>, chunked) instead of walking the targets collection. The topic auto-provisions on first publish (as in Reserved topics for users #13860). Every other push provider (FCM/APNS) still resolves device targets unchanged.
  • topics[] and targets[] paths are untouched.

New DX

// client — session only, no target registration
mqtt.subscribe(`users/${user.$id}`);

// server
await messaging.createPush(ID.unique(), 'Title', 'Body', users: [userId]);
// → delivered on users/<userId> ✅  (no createPushTarget needed)

Tests

  • E2E testUserTopicReceivesUserTargetedPush updated: creates only an enabled Appwrite provider (no push target), subscribes to users/<id>, sends users: [id], and asserts receipt.
  • Existing MQTT e2e (ownership, wildcard, topic campaigns, replay) and the push unit tests remain green.

The Appwrite push provider delivers to a user's reserved MQTT topic (users/<userId>)
that the user subscribes to with their session, so a device target is meaningless.
When the push provider is Appwrite, a users[] campaign now addresses each user id
directly and auto-provisions the topic on publish, instead of walking the targets
collection. Other push providers still resolve device targets as before.

DX: receiving a per-user push no longer requires account.createPushTarget — the
client just subscribes to users/<its id> over MQTT and the server sends users: [id].
@greptile-apps

greptile-apps Bot commented Sep 24, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

The PR appears safe to merge based on the reviewed changes.

Summary

The PR lets Appwrite push campaigns address existing users through their reserved MQTT topics without requiring device targets.

  • Registered targets remain in the recipient path.
  • The follow-up excludes expired targets when deciding whether a user needs direct topic delivery.
  • The MQTT end-to-end test checks receipt without target registration.

Reviews (3) · Last reviewed commit: "fix(messaging): keep MQTT fallback for u..."

@github-actions

github-actions Bot commented Sep 24, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → feat-mqtt-user-push-no-target (after).

Metric Before After Change
🚀 Requests/sec 158 148.3 🔴 -6.1%
⏱️ Latency P50 108.95 ms 114.74 ms 🔴 +5.3%
⏱️ Latency P95 255.57 ms 274.24 ms 🔴 +7.3%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 114.74 274.24 9,405 148.3 +18.67
Account 227.25 441.83 495 8.22 +44.43
TablesDB 110.32 220.13 5,115 82.17 +17.25
Storage 103.37 222.66 2,475 41.44 +7.08
Functions 164.39 322.15 1,320 22.7 +12.86

Top API waits (after)

API request Max wait (ms)
account.name.update 593.63
tablesdb.rows.get 581.32
functions.variables.update 571.83
account.prefs.update 559.32
functions.variables.create 501.15

Addresses review on the target-free user push:

- No longer skips the targets query when Appwrite is the default provider, so a
  user's FCM/APNS targets still receive; the reserved users/<id> topic is additive,
  used only for existing users that have no registered target.
- Validates that each users[] id exists before publishing, so a bogus id can't
  create a phantom users/ topic or be counted as delivered.
groupTargetsByProvider drops expired targets, so marking a user reached on an
expired target wrongly excluded them from the direct users/<id> delivery — an
expired-only user got nothing. Only non-expired targets now count as reached.
@ArnabChatterjee20k
ArnabChatterjee20k merged commit 1f4f7ae into main Sep 24, 2026
50 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.

2 participants