title: Firebase cloud device to device push notifications device token vs topics for
body: <p>I just got firebase function push notifications working for the first time.
  I'm monitoring a change with : </p>
  
  <pre><code>exports.observeNotifications = functions.database.ref('/notifications/{user_id}/{notification_id}').onWrite((change, context) =&gt; {
  </code></pre>
  
  <p>Later, I use :</p>
  
  <pre><code>const userQuery = admin.database().ref(`users/${from_user_id}/username`).once('value');
  const deviceToken = admin.database().ref(`/users/${user_id}/device_token`).once('value');
  </code></pre>
  
  <p>to retrieve the sender's userUID and device token which is later used with <code>sendToDevice()</code></p>
  
  <p>This works fine and is the method I see recommended everywhere, but I'm wondering why to do this over using topics in a user to user scenario. </p>
  
  <p>In the example of a chat application, every time a chat is sent, a value would be sent to <code>notifications/users/{uid} ...</code> and trigger the event. Then the value calls have to be made, promise handling has to be done, and then the push payload can be configured and sent.  </p>
  
  <p>With topics, when the user first loads up the application for the firs time, you could subscribe the user to a topic like "chat_notifications_usersIUID". This negates the need to fetch device tokens and go through the process of using promises and greatly simplifies the process of sending a notification to a specific user down to just pushing to a certain topic that is specific to the recipients UID. </p>
  
  <p>Are there any downsides to using topics over firebase function observes when sending a push notification from user to user(s). </p>