0
0
Firebasecloud~20 mins

Topic-based messaging in Firebase - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Topic-based Messaging Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
service_behavior
intermediate
2:00remaining
How does topic-based messaging deliver notifications?

In Firebase Cloud Messaging, when you send a message to a topic, how does the service deliver the message?

AThe message is delivered to all devices subscribed to the topic, regardless of their connection state.
BThe message is stored on the server and delivered only when the user opens the app.
CThe message is sent to a random device subscribed to the topic.
DThe message is sent only to devices currently connected to the server.
Attempts:
2 left
💡 Hint

Think about how topics help reach multiple devices at once.

Architecture
intermediate
2:00remaining
Choosing topics for user groups

You want to send notifications to users grouped by their interests. Which topic naming strategy is best to organize these groups?

ACreate a topic per user and send messages to each topic individually.
BUse a single topic for all users and filter messages on the client side.
CCreate one topic per interest, like 'sports', 'music', and subscribe users accordingly.
DUse random topic names and assign users randomly.
Attempts:
2 left
💡 Hint

Think about how topics help target groups efficiently.

security
advanced
2:30remaining
Securing topic subscriptions

Which method best prevents unauthorized users from subscribing to sensitive topics?

AUse public topic names and rely on obscurity to protect sensitive topics.
BAllow all users to subscribe to any topic without restrictions.
CUse Firebase Authentication and verify user identity before subscribing to topics on the client.
DSubscribe users to topics only on the server after verifying permissions.
Attempts:
2 left
💡 Hint

Consider where subscription control should happen for security.

Configuration
advanced
2:30remaining
Correct topic subscription code snippet

Which code snippet correctly subscribes a device to a topic using Firebase Cloud Messaging in JavaScript?

Firebase
import { getMessaging, getToken, onMessage } from 'firebase/messaging';

const messaging = getMessaging();

// Which option correctly subscribes to 'news' topic?
Amessaging.subscribe('news');
BgetToken(messaging).then(token => fetch('/subscribe', { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ token, topic: 'news' }) }));
Cmessaging.subscribeToTopic('news');
Dmessaging.subscribeTopic('news');
Attempts:
2 left
💡 Hint

Firebase client SDK does not directly subscribe to topics; it requires server interaction.

Best Practice
expert
3:00remaining
Handling topic messaging at scale

Your app has millions of users subscribed to multiple topics. What is the best practice to avoid hitting Firebase Cloud Messaging limits when sending topic messages?

ABatch topic messages and send them with delays to respect Firebase rate limits.
BSend one message per topic for all topics at once, ignoring rate limits.
CSend messages to individual device tokens instead of topics to avoid limits.
DUse random topic names to distribute load evenly.
Attempts:
2 left
💡 Hint

Think about how to manage large scale messaging without errors.