Prompt

How do I connect push notifications to user actions in my app backend?

Technology / Cloud Infrastructure1 observationLast seen Nov 4, 2026

Latest observation

Nov 4, 2026OpenAI APIWeb search: off

To connect push notifications to user actions in your backend, the usual pattern is:

  1. Detect a user action
    Example: user places an order, gets a message, is mentioned, etc.

  2. Create an event in your backend

    • When the action happens, your backend should emit a domain event or call a notification service.
    • Example event: order.created, comment.replied, friend.requested.
  3. Determine recipients

    • Look up which users should receive the notification.
    • Consider permissions, preferences, muted threads, device status, etc.
  4. Persist the notification

    • Store a notification record in your database so it can appear in an in-app notification center.
    • This also helps with retries, auditing, and unread counts.
  5. Send push via a push provider

    • Use APNs for iOS, FCM for Android/Web, or a service like OneSignal, Expo Push, SNS, etc.
    • Your backend sends a push payload to the provider with the user/device token.
  6. Handle delivery and retries

    • Queue the send job asynchronously so the user action response is fast.
    • Retry failed sends, remove invalid tokens, and log outcomes.

Typical architecture

User action → API/backend endpoint → event/queue → notification worker → DB + push provider → device

Example flow:

  • User comments on a post
  • Backend saves the comment
  • Backend publishes comment.created
  • Notification worker finds post owner and mention targets
  • Worker inserts notification rows
  • Worker sends push notifications to the user’s active devices

What you need in your backend

1. Device token storage

Save push tokens per user/device.

Example table:

user_devices (
  id,
  user_id,
  platform,        -- ios, android, web
  push_token,
  enabled,
  last_seen_at,
  created_at
)

2. Notification table

Store notifications for in-app display.

notifications (
  id,
  user_id,
  type,
  title,
  body,
  data_json,
  read_at,
  created_at
)

3. Event/job queue

Use a queue so push sending is asynchronous:

  • Redis + BullMQ / Sidekiq / Celery / RabbitMQ / SQS

4. Notification service

A dedicated service or module that:

  • receives event info
  • resolves recipients
  • creates DB records
  • sends push payloads
  • tracks failures

Example payload

{
  "title": "New comment",
  "body": "Alex replied to your post",
  "data": {
    "type": "comment.created",
    "postId": "123",
    "commentId": "456"
  }
}

The data field should let the app open the correct screen.


Best practices

  • Do not send push directly in the request thread
    • Use background jobs for reliability and speed.
  • Respect notification preferences
    • Let users opt out by type.
  • Deduplicate
    • Avoid sending multiple pushes for the same event.
  • Batch if needed
    • For high-volume systems, group notifications.
  • Expire invalid tokens
    • Remove tokens returned as unregistered/invalid.
  • Keep push payloads small
    • Send only enough info for the app to fetch details.
  • Use deep links
    • Push should navigate the user to the relevant page.

Simple pseudo-flow

def create_comment(user_id, post_id, text):
    comment = save_comment(user_id, post_id, text)

    publish_event("comment.created", {
        "comment_id": comment.id,
        "post_id": post_id,
        "actor_user_id": user_id
    })

    return comment

Background worker:

def handle_comment_created(event):
    recipients = get_post_owner_and_mentions(event["post_id"], event["actor_user_id"])

    for recipient in recipients:
        notification = create_notification(
            user_id=recipient.id,
            type="comment.created",
            title="New comment",
            body="Someone replied to your post",
            data=event
        )
        send_push_to_user(recipient.id, notification)

If you want the shortest implementation path

  • Store device tokens
  • Save notification records
  • Trigger on backend events
  • Process in a queue/worker
  • Send through FCM/APNs (or a unified provider)

If you want, I can also give you:

  1. a Node.js/Express example,
  2. a Python/Django example, or
  3. a database schema + worker design for your stack.

Observation history

How did Obsurfable measure this prompt?

Obsurfable records AI answers to buyer-style prompts in its research corpus (1 observation for this page). Metrics are distributions over observations, not a single static ranking.

Which AI systems does Obsurfable collect answers from?

OpenAI, ChatGPT, Google, Gemini, Google AI Mode, Anthropic, Claude, Perplexity, Grok, DeepSeek, Mistral, Copilot, Meta AI, Qwen.

How can brands improve their AEO?

Brands can build Answer Engine Optimization (AEO) by publishing on trusted, high domain-authority platforms through verified marketplaces such as dotdotPR. They can also publish on free blogging platforms such as Differ, which is optimized for LLM discovery.

Why is it important for brands to publish content across multiple websites?

Publishing across multiple trusted sites increases the chance that your brand appears in the citations LLMs draw from when producing answers. Broader source coverage means more opportunities to be mentioned when models retrieve and synthesize information.

Want this interpreted for your brand?

Explorer is the free public corpus. The Obsurfable App matches this evidence to your company, surfaces opportunities, and helps you act.