Varun Gupta
Varun Gupta

Reputation: 3112

Data transferred during Firebase Realtime Database value event

When I add a valueevent at a location in my Firebase realtime database, is the complete data at that location transferred every time the event is triggered (that is the value is changed at that location) or Firebase maintains a local copy and receives only the changed data internally and adds the rest from it local copy?

I am using the Javascript SDK in my react-native app. For e.g., let's say I have below data at a location where I add the value change handler

{
  "alarmAcknowledgements" : {
    "1539018000000" : {
      "-LO-1HsCjevE9M1R8vB3" : {
        "-LOJRLBaZv3PcoU72UQg" : {
          "response" : "Confirm",
          "timestamp" : 1539015009220
        },
        "-LOJW1eCZzd0T7YMxHTh" : {
          "response" : "Decline",
          "timestamp" : 1539016240020
        }
      }
    }
  }
}

I am listening on value change events at alarmAcknowledgements. If a new entry is added to alarmAcknowledgements, would the existing data be downloaded again or just the new entry.

The reason I am asking the question is because if Firebase receives the complete data at the location every time and the amount of data at that location increases:

  1. It will take more time to sync as time progresses.

  2. I will also incur more bandwidth charges as data increases at the location over time.

Upvotes: 1

Views: 88

Answers (1)

Doug Stevenson
Doug Stevenson

Reputation: 317497

Any data that has already been downloaded by a listener will be retained any memory for as long as the listener is active. Data is never downloaded a second time if it's unchanged.

Also, if you have disk persistence enabled, data cached to disk will not be downloaded again if it's unchanged on the server.

Upvotes: 4

Related Questions