How To Connect Data Between Different Firebase Services

Firebase category image

Connect data between different Firebase services that belongs together with this simple idea!

Firebase offers several services for storing data, including Firestore, Storage, and Realtime Database. However, it can be difficult to keep track of which data belongs together across service borders. Use my approach on how to connect data between different Firebase services. It has worked great for me in the past!

Want More Flutter Content?

Join my bi-weekly newsletter that delivers small Flutter portions right in your inbox. A title, an abstract, a link, and you decide if you want to dive in!

Unique indentifiers (UID)

When using Firebase Authentication, you get a UID per user. We can use this UID to identify corresponding data sets that belong to this user across services.

I also talk about it in my Firebase course because it’s a dead-simple way of how to connect data between different Firebase services.

Firebase Firestore (upper part) contains a collection with the same UID as a user in Firebase Authentication (lower part). We can identify user data by using a common UID across all Firebase services.
Firebase Firestore (upper part) contains a collection with the same UID as a user in Firebase Authentication (lower part). We can identify user data by using a common UID across all Firebase services.

When using Firestore, you can use the UID as a collection ID.

For example, in a TODO app, you may want to associate all TODOs with a specific user. To do this, you can either create a collection for each user and set the UID as the collection ID, or add a user property to each TODO that stores the UID.

The first approach requires fetching the entire collection, while the second method requires adding a filter to the query. This involves a bit more coding and may be slower for large collections.

The same principle applies to Cloud Storage. Make the UID part of the path to easily identify which items belong to which user.

Create UIDs

Firebase Authentication is an excellent tool for generating unique user IDs. Each registered user is assigned a unique identifier that remains the same, even if the app is deleted and reinstalled because it is associated with the user’s credentials, rather than the app itself.

Firebase Storage (upper part) contains a folder with the same UID as a user in Firebase Authentication (lower part). We can identify user data by using a common UID across all Firebase services.
Firebase Storage (upper part) contains a folder with the same UID as a user in Firebase Authentication (lower part). We can identify user data by using a common UID across all Firebase services.

Other possibilities are to create a microservice that generates those ids for you. You write a cloud function that returns a UID, make it accessible via a GET request, and deploy. Voilà, a super simple microservice!

However, you still need to think about where to store the identifier. Additionally, assigning an identifier to a user or device can be challenging. You will need a central instance to manage these identifiers and assignments in the end.Fortunately, Firebase Authentication provides this functionality out of the box.

Probably all major programming languages have built-in support for UID generation and you could even generate it in your mobile app. But it’s not a good idea to let the client create this vital identifier. Better do it in the backend!

Conclusion

In this article, I showed you my approach of how to connect data between different Firebase services. Unique identifiers are an easy way to accomplish this without too much trouble.

Level up your Firebase skills!

Check out my free email course on Firebase fundamentals, and grab your copy of my Firebase ebooks. Start building amazing apps with Firebase today!


Want More Flutter Content?

Join my bi-weekly newsletter that delivers small Flutter portions right in your inbox. A title, an abstract, a link, and you decide if you want to dive in!

Become A Firebase Expert!

Take a deep dive into Firebase and learn how to really handle their services. This ebook makes you an instant Firebase professional!

Flutter โค๏ธ Firebase

Get started with Firebase and learn how to use it in your Flutter apps. My detailed ebook delivers you everything you need to know! Flutter and Firebase are a perfect match!