Fireship · @fireship
Firestore Megachat - Let's Build a Chat App
Uploaded October 16, 2018 · Length 11:51
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.
- 0:00
[Music]
- 0:06
building a real-time chat app used to be
- 0:08
something that would take at least weeks
- 0:10
of development time but with firebase it
- 0:12
becomes almost trivial because the SDK
- 0:14
handles all the state management and
- 0:16
data syncing in between the client and
- 0:17
server for you it's so easy in fact that
- 0:20
I built an entire chat app in the last
- 0:21
24 hours that you can use right now and
- 0:23
over the next few minutes I'll show you
- 0:25
exactly how I built it using an angular
- 0:27
fire and fire store if you're just
- 0:29
finding the channel like and subscribe
- 0:30
and if you leave a comment below you'll
- 0:32
have a chance to win either a sticker or
- 0:33
a t-shirt on the livestream later this
- 0:35
week now the first thing I want to talk
- 0:37
about in this video is data modeling
- 0:39
because there's no one-size-fits-all for
- 0:41
every chat feature the first thing every
- 0:43
app will need is a user authentication
- 0:45
system and then some public user profile
- 0:47
information saved in a user's collection
- 0:49
and firestore that's pretty
- 0:51
straightforward but you have a lot of
- 0:52
different options when it comes to
- 0:54
modeling the relationship between users
- 0:56
chats and individual messages
- 0:58
I think the logical first approach that
- 1:00
most people would take is to set up a
- 1:02
collection of chats and then for each of
- 1:04
these chats create a sub collection of
- 1:06
messages this is a good way to go
- 1:08
because you can save all of your chat
- 1:09
metadata on one small document and then
- 1:11
query as many messages as you need from
- 1:14
the sub collection and as an alternative
- 1:15
you might make this a root collection so
- 1:18
you can query the messages across all of
- 1:19
the different chats throughout your
- 1:21
application for example a root
- 1:23
collection will allow you to query all
- 1:24
the messages for a specific user across
- 1:26
all the different chats that they're
- 1:28
participating in I think this approach
- 1:30
is the most flexible but the drawback is
- 1:32
that you need to execute a document read
- 1:34
for every message that you show in the
- 1:36
UI in this video we're going to take a
- 1:38
completely different approach by
- 1:39
modeling each chat as its own document
- 1:41
and then embedding the messages for that
- 1:43
chat on the document this method is fast
- 1:46
and simple but there are some
- 1:47
limitations first we can no longer query
- 1:50
the individual messages because they're
- 1:51
embedded on the document we can only
- 1:53
sort them client side and the second
- 1:55
thing is that documents are limited to
- 1:57
one megabyte of data which is
- 1:59
conservatively somewhere between 250 and


