See all Blogs

Shahroz Bakht

Measuring Real-Time Database Performance with Firebase Performance Monitoring

Building an app with a real-time database is incredibly fast but knowing how your database operations are for your users in the real world is also vital for a good app developer. Many people in the tech industry, use field measurements for real user monitoring (RUM) for measuring app performance and especially to figure user experience.

Firebase performance monitoring provides free and cross-platform service to help its user collect and analyze RUM data for your app or website. It measures metrics like time to first paint and HTTP request performances. Because the real-time database uses long-running websocket connections rather than separate HTTP requests. This will need custom traces to monitor the performance of your database performance.

We built a firebase powered implementation of the standard todoMVC app in react using ReactFire library for this

  • Adding, updating, or removing an item in the to-do list make a change in real-time data directly. This operation appears to be instantaneous and immediately adds to the new to-do to the local listener.
  • To figure out how much time it takes, we create a new function called tracePromise to help log a custom trace for any action which returns a promise and, then we add a simple custom trace called add todo.
  • It takes about 100ms in most cases, with 160ms being the worst case. If we break down in countries, this operation is faster in the US than in other countries.
  • Most real-time database instances are in the US, which can have an impact on latency for users all around the world.
  • Data travels at the speed of light for the two points on the opposite side of the earth the speed of light alone adds 66ms of latency, not including any actual network or processing latency along the way. That is why adding RUM to the app is very critical.
  • Realtime Database is now expanding to more regions all over the world to improve latency.
  • The launch of the Belgium region in late 2020 has also improved latency.
  • Adding second real-time Database instances to the app in the Belgium region to observe the effect on latency by assigning each user to a random database instance and adding a custom attribute to the performance monitoring traces so that we can filter the location. Then deploying these changes and wait for a new user to come in. After few days, we will see that our distribution has two peaks, and our experiment worked.
  • Now we can randomly assign users to any database instance it can be either close to them or far away.
  • If we look into data more, we can see that the German user has a really fast connection to the Belgian instances. They can now get an update in 22ms which is a huge improvement in comparison with US instances.


Looking at RUM data we can see that adding a new database region can make our app perform faster by assigning them a suitable region in terms of their location which also adds to a better experience for the user.

  See all Blogs