Fireship · @fireship

Firestore Megachat - Let's Build a Chat App

Uploaded October 16, 2018 · Length 11:51

Firestore Megachat - Let's Build a Chat App

Summary

Building a real-time chat app with Firestore, Angular Fire, and Firebase, including data modeling, user authentication, and chat functionality.

  • firestore chat app
  • angular fire tutorial
  • firebase real-time chat
  • data modeling in firestore
  • user authentication with firebase

Transcript preview

The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.

  1. 0:00

    [Music]

  2. 0:06

    building a real-time chat app used to be

  3. 0:08

    something that would take at least weeks

  4. 0:10

    of development time but with firebase it

  5. 0:12

    becomes almost trivial because the SDK

  6. 0:14

    handles all the state management and

  7. 0:16

    data syncing in between the client and

  8. 0:17

    server for you it's so easy in fact that

  9. 0:20

    I built an entire chat app in the last

  10. 0:21

    24 hours that you can use right now and

  11. 0:23

    over the next few minutes I'll show you

  12. 0:25

    exactly how I built it using an angular

  13. 0:27

    fire and fire store if you're just

  14. 0:29

    finding the channel like and subscribe

  15. 0:30

    and if you leave a comment below you'll

  16. 0:32

    have a chance to win either a sticker or

  17. 0:33

    a t-shirt on the livestream later this

  18. 0:35

    week now the first thing I want to talk

  19. 0:37

    about in this video is data modeling

  20. 0:39

    because there's no one-size-fits-all for

  21. 0:41

    every chat feature the first thing every

  22. 0:43

    app will need is a user authentication

  23. 0:45

    system and then some public user profile

  24. 0:47

    information saved in a user's collection

  25. 0:49

    and firestore that's pretty

  26. 0:51

    straightforward but you have a lot of

  27. 0:52

    different options when it comes to

  28. 0:54

    modeling the relationship between users

  29. 0:56

    chats and individual messages

  30. 0:58

    I think the logical first approach that

  31. 1:00

    most people would take is to set up a

  32. 1:02

    collection of chats and then for each of

  33. 1:04

    these chats create a sub collection of

  34. 1:06

    messages this is a good way to go

  35. 1:08

    because you can save all of your chat

  36. 1:09

    metadata on one small document and then

  37. 1:11

    query as many messages as you need from

  38. 1:14

    the sub collection and as an alternative

  39. 1:15

    you might make this a root collection so

  40. 1:18

    you can query the messages across all of

  41. 1:19

    the different chats throughout your

  42. 1:21

    application for example a root

  43. 1:23

    collection will allow you to query all

  44. 1:24

    the messages for a specific user across

  45. 1:26

    all the different chats that they're

  46. 1:28

    participating in I think this approach

  47. 1:30

    is the most flexible but the drawback is

  48. 1:32

    that you need to execute a document read

  49. 1:34

    for every message that you show in the

  50. 1:36

    UI in this video we're going to take a

  51. 1:38

    completely different approach by

  52. 1:39

    modeling each chat as its own document

  53. 1:41

    and then embedding the messages for that

  54. 1:43

    chat on the document this method is fast

  55. 1:46

    and simple but there are some

  56. 1:47

    limitations first we can no longer query

  57. 1:50

    the individual messages because they're

  58. 1:51

    embedded on the document we can only

  59. 1:53

    sort them client side and the second

  60. 1:55

    thing is that documents are limited to

  61. 1:57

    one megabyte of data which is

  62. 1:59

    conservatively somewhere between 250 and