Firebase real time database Vs. Firestore

Firebase दो databases offer करता है: Realtime Database सब कुछ एक बड़े JSON tree की तरह store करता है, basic syncing के लिए simple और fast, जबकि Cloud Firestore structured collections और documents richer queries और better scaling के साथ इस्तेमाल करता है।

10 min read · 7 cards · 2 checks

Read in: English · हिन्दी · ગુજરાતી


Theory

दो Databases, एक Choice

FestConnect Mobile को cloud में data store करना है, events, registrations, और Firebase आपको दो NoSQL databases का choice देता है: Realtime Database और Cloud Firestore। दोनों hosted हैं, दोनों real time में sync होते हैं, दोनों offline काम करते हैं। पर ये data को अलग तरीके से organise करते हैं और अलग needs को suit करते हैं।

Storage code लिखने से पहले (अगली unit), आपको जानना चाहिए कौन सा choose करना है और क्यों। यह lesson इन्हें compare करता है तो आप deliberately choose कर सकें। Short में: Firestore newer, ज़्यादा structured option है; Realtime Database older, simpler वाला है।

Theory

हर एक Data कैसे Store करता है

Realtime Database आपकी पूरी app का data एक बड़े JSON tree की तरह store करता है, keys और values की एक single nested structure। यह simple है और basic real-time syncing के लिए extremely fast है, और यह लंबे समय से मौजूद है। Downside: जैसे data grow होता है, वह एक tree deeply nested और awkward हो सकता है, और इसकी querying limited है (simple, shallow queries), तो complex data structure और scale करना harder है।

Cloud Firestore इसके बजाय data को documents के collections में organise करता है (जो subcollections hold कर सकते हैं), वही model जो आपने web side पर देखा। यह structure richer queries support करता है और ज़्यादा flexibly scale करता है, थोड़ा ज़्यादा involved होने की कीमत पर। यह newer, generally recommended choice है।

At a glance

AspectRealtime DatabaseCloud Firestore
Data Modelएक बड़ा JSON treeDocuments के collections (subcollections के साथ)
QueriesSimple, limited, shallowRicher, ज़्यादा powerful
Scalingकम flexibleबेहतर scale करता है
MaturityOlder, बहुत low latencyNewer, नई apps के लिए generally recommended
दोनोंReal-time sync, offline supportReal-time sync, offline support

Formula

कौन सा Choose करें

ज़्यादातर नई apps के लिए, FestConnect के events और registrations जैसे structured data सहित, Firestore sensible default है: इसका collections-and-documents model और richer queries real app data fit करते हैं, और यह अच्छी तरह scale करता है।

Realtime Database के लिए reach कीजिए जब आपकी needs बहुत simple और low-latency हों, basic data जो naturally एक JSON tree में map होता है, या जब आप एक existing project पर काम कर रहे हों जो पहले से इस पर built है। दोनों अच्छे हैं; decision इस पर आता है आपका data कितना structured है और आपकी queries कितनी complex होनी चाहिए। जब unsure हों, Firestore safer modern pick है।

Quiz

Cloud Firestore की तुलना में Firebase Realtime Database आपकी app का data कैसे store करता है?

  1. दोनों rows और columns वाले SQL tables की तरह data store करते हैं
  2. Realtime Database सब कुछ एक बड़े JSON tree की तरह store करता है, जबकि Firestore data को documents के collections में organise करता है
  3. Realtime Database collections और documents इस्तेमाल करता है; Firestore एक JSON tree इस्तेमाल करता है
  4. कोई भी real time में data sync नहीं कर सकता
Show the answer

Realtime Database सब कुछ एक बड़े JSON tree की तरह store करता है, जबकि Firestore data को documents के collections में organise करता है

Realtime Database सारा data एक single बड़े JSON tree की तरह store करता है, जबकि Cloud Firestore data को documents के collections में organise करता है (जो subcollections contain कर सकते हैं)। Option A wrong है: दोनों NoSQL हैं, कोई भी fixed rows और columns वाले SQL tables इस्तेमाल नहीं करता। Option C इन्हें reverse करता है: Firestore है जो collections/documents इस्तेमाल करता है और Realtime Database है जो JSON tree इस्तेमाल करता है, उल्टा नहीं। Option D false है: दोनों databases real-time syncing (और offline) support करते हैं। Core distinction है data model: एक JSON tree (Realtime Database) बनाम structured collections और documents (Firestore)।

Think first

Firestore का Collections-and-Documents Model एक JSON Tree से Better क्यों Scale और Query करता है?

दोनों NoSQL हैं और real time में sync होते हैं। Growing apps के लिए Firestore की structure अक्सर better क्यों है? फिर tap कीजिए।

Show the answer

क्योंकि Firestore का data कई छोटे, independent DOCUMENTS में break होता है collections में grouped, जो आपको exactly वही fetch और query करने देता है जो आपको चाहिए, जबकि Realtime Database का single JSON tree आपकी चाही ज़रूरत से ज़्यादा खींचता है और सिर्फ़ shallow queries offer करता है। Realtime Database में, सब कुछ एक nested tree में रहता है, और queries limited और largely shallow हैं, तो complex data structure करना अक्सर awkward choices force करता है, और चूँकि tree एक connected structure है, इसका हिस्सा पढ़ना nested data का एक chunk load करने की ज़रूरत हो सकता है जो आपको नहीं चाहिए, जो bandwidth waste करता है और data grow होने के साथ चीज़ें slow करता है (एक problem जिसे कभी-कभी 'fan-out' कहते हैं)। Firestore इसके बजाय data को collections के अंदर separate documents की तरह store करता है: आप real filters और ordering से एक collection query कर सकते हैं, सिर्फ़ वही specific documents retrieve कर सकते हैं जो match करते हैं, और results के through page कर सकते हैं, unrelated data drag किए बिना। चूँकि documents independent units हैं, Firestore इन्हें अपने infrastructure के across ज़्यादा flexibly distribute और scale भी कर सकता है, और इसकी query performance RESULT set के size पर depend करती है, पूरे dataset पर नहीं, तो data grow होने के साथ यह fast रहता है। Subcollections आपको related data (एक event की registrations) nest करने देते हैं parent document को bloat किए बिना। Trade-off यह है कि Firestore के साथ काम करना थोड़ा ज़्यादा structured है, और Realtime Database अभी भी बहुत simple, ultra-low-latency needs के लिए जीत सकता है। पर real queries वाली typical growing apps के लिए, Firestore का document model यही वजह है यह better scale और query करता है, और यही वजह है यह आज usual default है। छोटे independent documents एक giant tree को beat करते हैं जब data और queries grow होते हैं।

Summary

Key takeaways

  • Firebase दो NoSQL databases offer करता है: Realtime Database और Cloud Firestore; दोनों real time में sync होते हैं और offline काम करते हैं।
  • Realtime Database सारा data एक बड़े JSON tree की तरह store करता है: simple और बहुत low latency, पर limited querying और कम flexible scaling।
  • Cloud Firestore data को documents के collections में organise करता है (subcollections के साथ): richer queries और better scaling।
  • Firestore newer है और नई apps के लिए generally recommended है, especially structured data के साथ।
  • Structured data और complex queries के लिए Firestore choose कीजिए (usual default); बहुत simple, low-latency needs या existing projects के लिए Realtime Database।
  • Firestore बेहतर scale और query करता है क्योंकि independent documents आपको exactly वही fetch करने देते हैं जो चाहिए, एक connected JSON tree के unlike।
  • Memory hook: Realtime Database एक JSON tree है, Firestore documents के collections हैं; Firestore modern default है।

Study this properly

This page is the lesson to read. In Gri-Learn the same topic is a graded deck: the self-checks are scored and your weak topics are tracked. Free to start.

Start this topic

Already have an account? Sign in

More from FirebaseUI Auth authentication

Gri-Learn · syllabus-mapped B.C.A. lessons in English, Hindi and Gujarati

Firebase real time database Vs. Firestore · Advance Mobile Application Development - II (Major-15-02) · Gri-Learn