1
votes

I am trying to make feed/timeline where a user can follow - Category,Album or another User. Every time a picture is added to Category,Album,User it should appear on the timeline. I am trying to model my database so it requires 1-2 get requests only.

  • One idea for the solution is fan-out structure, But how do i make the multi-path update in Firestore? How can i update all the followers timelines when someone uploads a photo ?
  • How do i structure the database when i cant query on sub-collections? Should i just make one collection which contains all user timeline posts as separate documents, which will be ridiculous amount of duplicated data.
  • Is there any other way instead of fan-out to structure a user timeline ?
2

2 Answers

1
votes

But how do I make the multi-path update in Firestore?

The equivalent of Firebase Realtime Database's multi-path updates, are called batched writes in Cloud Firestore. You can read more in the documentation on batches writes.

0
votes

Flat.

root
  pictures
    uid-abc123
      url:"http://test.com/img1.jpg"
      owner:useriduid,
      created: 1529333679449
    uid-abc1billion
      url:"http://test.com/img1billion.jpg"
      owner:useriduid,
      created: 1529333679300

Querying and security rules are then easy as pie. You can add indexing and it's very scalable.

Re multipath writes, use batched writes.