title: Efficient way to query posts of multiple users from a node in Firebase
body: <p>I am building a social application which allows users to follow each other and get a feed of posts made by users they follow. Currently, am planning my data to be stored as given below, however, am not sure if it will scale.</p>
  
  <pre><code>{
    "users": {
      "alovelace": {
        "name": "Ada Lovelace",
        "follows": { 
  
                     "ghopper": true,
                     "eclarke": true,
                     "john": true
                     //+100 more maybe
        },
      },
      "ghopper": { ... },
      "john": { ... },
      "eclarke": { ... }
  
      //all the users....
    },
  
    "posts": {
  
        "p1": {
          "user": "eclarke",
          "post": "Its a wonderful day today.",
          "timestamp": 1459361875337
        },
        "p2": {
          "user": "john",
          "post": "The laptop seems to be malfunctioning.",
          "timestamp": 9454361875332
        },
        "p3": {
          "user": "ghopper",
          "post": "The bus is late.",
          "timestamp": 6593618235336
        },
        "p4": {
          "user": "someotheuser",
          "post": "The relay seems to be malfunctioning.",
          "timestamp": 1459361875337
        },
        "p5": {
          "user": "eclarke",
          "post": "The relay seems to be malfunctioning.",
          "timestamp": 5459361875331
        },
        "p6": {
          "user": "alovelace",
          "post": "The relay seems to be malfunctioning.",
          "timestamp": 3459361875334
        }
        //1,000,000+ posts maybe present. 
    }
  }
  </code></pre>
  
  <p>All the users are stored in <code>users</code> node along with whom they follow. And all the posts made by all users are stored in the node posts. While users of the platform may scale to 1000's the no. of posts should easily scale to 1,000,000+. I will need query the data in the following ways:</p>
  
  <ol>
  <li><p>For the user, <code>alovelace</code> get the recent posts of the users the users
  follow. In our case, posts of <code>ghopper</code>,<code>eclarke</code> and <code>john</code>. This
  has to be sorted by time and paginated. As we may only show 10 posts
  at a time.</p></li>
  <li><p>For the user `john', show all his posts on his profile. </p></li>
  </ol>
  
  <p>Is firebase the right DB for this sort of use case. Is the structure am following scalable? Is there anything else I have to consider?</p>