How to Properly Design Firebase FCM Push Notifications for Multi-Device Apps

Push notification issues such as duplicate alerts or devices not receiving messages usually stem from poor backend token management, not from Firebase itself.

This guide explains the correct way to design a scalable, multi-device push notification system using Firebase Cloud Messaging (FCM).

The Real Problem

Most push notification failures happen because of backend design mistakes, such as:

  • Only one device token is stored per user
  • Old tokens not removed
  • Duplicate tokens saved
  • Invalid tokens were not cleaned
  • Notifications sent synchronously inside API requests

These issues lead to duplicate alerts, missed notifications, and poor scalability.

The Correct Architecture

A proper, production-ready push system should follow this structure:

Mobile App → Backend → Queue → Notification Service → FCM → Device

Key principle: Never send push notifications directly inside the main API request.

Instead, use queue-based background processing to handle notifications asynchronously. This improves reliability, performance, and scalability.

Correct Database Design

Each user must support multiple devices. That means storing multiple device tokens per user.
User {
  id
  email
  deviceTokens: [String]
}

Why this matters:

Users often log in from multiple devices (phone, tablet, web, etc.). If you store only one token per user, multi-device notifications will break.

Proper Token Handling

1. On Login

Add the device token only if it doesn’t already exist.
if (!user.deviceTokens.includes(newToken)) {
   user.deviceTokens.push(newToken)
}
This prevents duplicate tokens and duplicate notifications.

2. On Logout

Remove the device token when a user logs out.
fuser.deviceTokens = user.deviceTokens.filter(
   token => token !== logoutToken
)
This helps logged-out devices stop receiving notifications.

3. On Firebase Errors

When sending notifications, FCM may return errors like:
  • Invalid token
  • Not registered
When this happens, remove the token immediately from the database. Keeping invalid tokens causes delivery failures and wasted API calls.

Sending Notifications

Use the Firebase Admin SDK and send multicast notifications to all user devices.
sendMulticast({
   tokens: user.deviceTokens,
   notification: {
     title: "Wallet Credited",
     body: "₹500 added successfully"
   }
})

For Production Scale

  • Send to a maximum of 500 tokens per batch
  • Use queues
  • Process notifications in background workers
  • Retry failures intelligently

Why This Architecture Works?

This approach:

  • Prevents duplicate notifications
  • Fixes missing deliveries
  • Supports multi-device logins correctly
  • Scales to large user bases
  • Keeps your system production-ready

Most push notification issues are not caused by Firebase, they’re caused by poor token lifecycle management and synchronous sending patterns.

Design your backend properly, and FCM will work reliably at scale.

– Radhika Raghuvanshi