SlideShare a Scribd company logo
1 of 24
Case Study:
Seamless database migration - from
Firebase real-time database to
PostgreSQL
8th Oct, 2020
Software Development Manager
Pin-Ying Tu
spirit@inline.tw
/ 23
About
• High-scale software engineer
• US$1M+ spent on cloud
• Hiring Manager :-)
• Ph.D. NTUT
• 8 years software engineering
experience
• inline
Case Study: Seamless database migration - from Firebase real-time database to PostgreSQL 1
github.com/dbi1463
/ 23
inline services 1/2
• Start from automated queueing
– Realtime status update
• Booking management
– Multiple sources
– Full capcaity management
Case Study: Seamless database migration - from Firebase real-time database to PostgreSQL 2
/ 23
inline services 2/2
• CRM
– Actionable insights
– Campaign SMS
– Survey and coupon
• Takeout and delivery and more
– Menu management
– Integration with multiple delivery
partners
Case Study: Seamless database migration - from Firebase real-time database to PostgreSQL 3
/ 23
We are growing, quickly
Case Study: Seamless database migration - from Firebase real-time database to PostgreSQL 4
/ 23
Why did we choose Firebase real-time database?
• Less backend work
• Real-time data synchronization is a very important feature
Case Study: Seamless database migration - from Firebase real-time database to PostgreSQL 5
/ 23
Sharding for growth
Case Study: Seamless database migration - from Firebase real-time database to PostgreSQL
main
Shard 1 Shard 2 Cust 1
Cust 2 Cust 3 Cust 4
Without our own API
server, clients need to be
aware of which shard to
connect
Moving data around
shards takes time and
money
Shards got slow again
when data growth
Script to move data from
master to the new shard
and deploy functions to
each shard
6
/ 23
New synchronization mechanism 1/2
• Minimize memory usage in client-side endpoints
– Firebase iOS SDK consume huge memory if off-line mode is enabled
– Firebase iOS SDK read/write performance become very bad when
the network environment is not good
• We want a faster and smaller memory footprint sync method
– Data synchronization between multiple devices
• 95% reservations should be synchronized in 5 seconds
– Support off-line first
• Still provide good user experience (do not block user operations)
• Can not lose any reservation even the network environment is not good
–Seamless
• No service down time
• The restaurants are not aware of the changes
Case Study: Seamless database migration - from Firebase real-time database to PostgreSQL 7
/ 23
New synchronization mechanism 2/2
Case Study: Seamless database migration - from Firebase real-time database to PostgreSQL
Persistent,
ordered, and
parallel requests
Three long polling
APIs for better UX
experience
Trigger cloud
functions
Publish a sync
event to PubSub
Background
jobs receive
sync events
Background jobs handle the
out of order issue and write
data to Elasticsearch
Background jobs touch
Redis to notify hooked
long polling requests
Monitor the pending
writes requests
Monitor the cost distribution
Unsync reporter
8
/ 23
Decouple Firebase SDK, finally
Case Study: Seamless database migration - from Firebase real-time database to PostgreSQL
+request(in path) : InvokableRestRequest
RestClientImpl
+request(in path) : InvokableRestRequest
<<interface>>
RestClient
+query(in name , in value)
+where(in name, in value)
+get(in handler : ResponseHandler)
+post(in handler : ResponseHandler)
+put(in handler : ResponseHandler)
+delete(in handler : ResponseHandler)
+getPlainText(in handler : ResponseHandler)
+invoke(in method : string, in body : object, in handler : ResponseHandler)
InvokableRestRequestImpl
InvokableRestRequest
+create(in reservation)
MutableReservationFirebaseWebService
<<interface>>
MutableReservationWebService
+create(in reservation)
MutableReservationRestfulWebService
+get() : MutableReservationWebServiceProvider
MutableReservationWebServiceProvider
+add(in request : SerializableRequest)
-persist(in request : SerializableRequest)
-remove(in request : SerializableRequest)
+runNext()
SerializableRestRequestQueue
+invoke()
+init()
-id : string
-timestamp : long
-completedURL : string
-httpHeaders : [string: string]
-body : object
-handler : ResponseHandler
SerializableRequest
Codeable
Only serialize the write operations, i.e., POST, PUT, and
DELETE
The requests must be
executed in order
Move the original Firebase
implementation to here
9
/ 23
Performance improvement
Case Study: Seamless database migration - from Firebase real-time database to PostgreSQL
Off-line to online Bad network
Create and edit n reservations
and wait all reservations were
synchronized to all devices
X: time
Y: pending writes per second
Blue: Firebase SDK
Red: Firebase REST API
Normal network
10
/ 23
The device sync dashboard
Case Study: Seamless database migration - from Firebase real-time database to PostgreSQL
Device-to-device cost by location Upload latency by location
Device-to-device cost by day
11
/ 23
So far so good, but we want better
• Scaling goals we want to achieve
– 99.99% availability of customer-facing services, with:
– Fast and flexible queries
• Like other database, without index the query is very slow
• Firebase real-time database query only supports one index
• Need to build the indices programmatically by ourselves
– Fully managed DB shard and persistence migrations
• Firebase team migrate the instances without any notification
• We can not schedule the migration
• During the time to rebuild in-memory indices after migration, all accesses to
Firebase database are queued
– Able to scale workers horizontally in one AZ and across Azs
• Firebase cloud functions have 1,000 deployment quota
Case Study: Seamless database migration - from Firebase real-time database to PostgreSQL
As a result, we decide to migrate our main database.
12
/ 23
Architecture Evolution
• Current architecture
• New architecture
Case Study: Seamless database migration - from Firebase real-time database to PostgreSQL
Persistent,
ordered, and
parallel requests
inline APIs write to PostgreSQL and
touch Redis to notify the subscribed
WebSocket handlers
Devices receive events through
WebSocket with some APIs to
improve UX experience
Background jobs to perform
the functionalities of the
original cloud functions
13
/ 23
Phase 0 – Performance evaluation
• Make sure PostgreSQL can meet our performance goals
– 50 M data set
– Maximum query time
• Current 36ms avg
Goal: 200 rows in 30 ms
– Queries per second
• Current: 117/sec sustained
Goal (5x): 585/sec sustained
– Inserts/Updates per second
• Current: 40/sec sustained
Goal (5x): 200/sec sustained
Case Study: Seamless database migration - from Firebase real-time database to PostgreSQL 14
Connection
pool
/ 23
Phase 1 – Sync new reservations to PostgreSQL
• Not breaking any existing system
– Still a few restaurants use the version before long polling
– Not every restaurant upgrade app frequently
• Use feature toggle to control the switch between two methods
Case Study: Seamless database migration - from Firebase real-time database to PostgreSQL 15
/ 23
Phase 2 – Make sure WebSocket works
• Use feature toggle (remote control) to switch between
WebSocket and long polling
Case Study: Seamless database migration - from Firebase real-time database to PostgreSQL 16
/ 23
Phase 3 – Copy old reservations to PostgreSQL
• Controllable copy scopes
– By brand or by shard
Case Study: Seamless database migration - from Firebase real-time database to PostgreSQL 17
/ 23
Phase 4 – Move cloud functions
• Totally 31 cloud functions moved
– Use feature toggle to enable/disable the cloud functions
Case Study: Seamless database migration - from Firebase real-time database to PostgreSQL 18
/ 23
Phase 5 – inline APIs
• Implement the new inline APIs and clients adopt APIs
– Also write back to Firebase
• Fully tested with all combination on beta
– Firebase REST API
– inline API
– WebSocket
– Long polling
Case Study: Seamless database migration - from Firebase real-time database to PostgreSQL 19
/ 23
Phase 6 – controlled roll out
• Planned roll out
– Start to migrate a company that is willing to try new method
– Start to migrate shard by shard until all shards migrated
Case Study: Seamless database migration - from Firebase real-time database to PostgreSQL 20
/ 23
Phase 7 - Remove Firebase dependency
• After migrate all shards and companies, trigger the force
upgrade notification
• Remove Firebase dependency from inline APIs
Case Study: Seamless database migration - from Firebase real-time database to PostgreSQL 21
/ 23
Lession learned 1/2
• Abstraction layer
– Try to minimize vendor lock-in for fundamentals of your system
– Even if it costs more in time during the first implementation
• Cost estimation
– Don't forget to turn off the load generator
– Set up a spending rate monitor
• Planning is important
– Help design thinking
• Testing is important
– Unit testing, end-to-end testing, and load testing all help us not
breaking anything important to our customers depend on
Case Study: Seamless database migration - from Firebase real-time database to PostgreSQL 22
/ 23
Lession learned 2/2
• Always contact the cloud service support team
– They have more than the public information and wouldn’t let you
know if you did not ask
• Choose cloud service platform carefully
– Do some evaluation for your needs before choosing a cloud service
platform
• Data synchronization is extreme difficult
– Do not build your own synchronization unless the current solution
can not meet your needs
Case Study: Seamless database migration - from Firebase real-time database to PostgreSQL
Any question?
23

More Related Content

What's hot

Event-Driven Stream Processing and Model Deployment with Apache Kafka, Kafka ...
Event-Driven Stream Processing and Model Deployment with Apache Kafka, Kafka ...Event-Driven Stream Processing and Model Deployment with Apache Kafka, Kafka ...
Event-Driven Stream Processing and Model Deployment with Apache Kafka, Kafka ...
Kai Wähner
 
From Batch to Streaming ET(L) with Apache Apex at Berlin Buzzwords 2017
From Batch to Streaming ET(L) with Apache Apex at Berlin Buzzwords 2017From Batch to Streaming ET(L) with Apache Apex at Berlin Buzzwords 2017
From Batch to Streaming ET(L) with Apache Apex at Berlin Buzzwords 2017
Thomas Weise
 
Jim Dowling – Interactive Flink analytics with HopsWorks and Zeppelin
Jim Dowling – Interactive Flink analytics with HopsWorks and ZeppelinJim Dowling – Interactive Flink analytics with HopsWorks and Zeppelin
Jim Dowling – Interactive Flink analytics with HopsWorks and Zeppelin
Flink Forward
 

What's hot (20)

Event-Driven Stream Processing and Model Deployment with Apache Kafka, Kafka ...
Event-Driven Stream Processing and Model Deployment with Apache Kafka, Kafka ...Event-Driven Stream Processing and Model Deployment with Apache Kafka, Kafka ...
Event-Driven Stream Processing and Model Deployment with Apache Kafka, Kafka ...
 
Zoltán Zvara - Advanced visualization of Flink and Spark jobs

Zoltán Zvara - Advanced visualization of Flink and Spark jobs
Zoltán Zvara - Advanced visualization of Flink and Spark jobs

Zoltán Zvara - Advanced visualization of Flink and Spark jobs

 
Portable Streaming Pipelines with Apache Beam
Portable Streaming Pipelines with Apache BeamPortable Streaming Pipelines with Apache Beam
Portable Streaming Pipelines with Apache Beam
 
Hadoop made fast - Why Virtual Reality Needed Stream Processing to Survive
Hadoop made fast - Why Virtual Reality Needed Stream Processing to SurviveHadoop made fast - Why Virtual Reality Needed Stream Processing to Survive
Hadoop made fast - Why Virtual Reality Needed Stream Processing to Survive
 
Jim Dowling - Multi-tenant Flink-as-a-Service on YARN
Jim Dowling - Multi-tenant Flink-as-a-Service on YARN Jim Dowling - Multi-tenant Flink-as-a-Service on YARN
Jim Dowling - Multi-tenant Flink-as-a-Service on YARN
 
Flink Forward SF 2017: Bill Liu & Haohui Mai - AthenaX : Uber’s streaming pro...
Flink Forward SF 2017: Bill Liu & Haohui Mai - AthenaX : Uber’s streaming pro...Flink Forward SF 2017: Bill Liu & Haohui Mai - AthenaX : Uber’s streaming pro...
Flink Forward SF 2017: Bill Liu & Haohui Mai - AthenaX : Uber’s streaming pro...
 
From Batch to Streaming ET(L) with Apache Apex at Berlin Buzzwords 2017
From Batch to Streaming ET(L) with Apache Apex at Berlin Buzzwords 2017From Batch to Streaming ET(L) with Apache Apex at Berlin Buzzwords 2017
From Batch to Streaming ET(L) with Apache Apex at Berlin Buzzwords 2017
 
Flink Forward Berlin 2017: Steffen Hausmann - Build a Real-time Stream Proces...
Flink Forward Berlin 2017: Steffen Hausmann - Build a Real-time Stream Proces...Flink Forward Berlin 2017: Steffen Hausmann - Build a Real-time Stream Proces...
Flink Forward Berlin 2017: Steffen Hausmann - Build a Real-time Stream Proces...
 
Maximilian Michels - Flink and Beam
Maximilian Michels - Flink and BeamMaximilian Michels - Flink and Beam
Maximilian Michels - Flink and Beam
 
Production Ready Kafka on Kubernetes (Devandra Tagare, Lyft) Kafka Summit SF ...
Production Ready Kafka on Kubernetes (Devandra Tagare, Lyft) Kafka Summit SF ...Production Ready Kafka on Kubernetes (Devandra Tagare, Lyft) Kafka Summit SF ...
Production Ready Kafka on Kubernetes (Devandra Tagare, Lyft) Kafka Summit SF ...
 
Flink at netflix paypal speaker series
Flink at netflix   paypal speaker seriesFlink at netflix   paypal speaker series
Flink at netflix paypal speaker series
 
Metrics Are Not Enough: Monitoring Apache Kafka and Streaming Applications
Metrics Are Not Enough: Monitoring Apache Kafka and Streaming ApplicationsMetrics Are Not Enough: Monitoring Apache Kafka and Streaming Applications
Metrics Are Not Enough: Monitoring Apache Kafka and Streaming Applications
 
Jim Dowling – Interactive Flink analytics with HopsWorks and Zeppelin
Jim Dowling – Interactive Flink analytics with HopsWorks and ZeppelinJim Dowling – Interactive Flink analytics with HopsWorks and Zeppelin
Jim Dowling – Interactive Flink analytics with HopsWorks and Zeppelin
 
Flink Forward Berlin 2017: Jörg Schad, Till Rohrmann - Apache Flink meets Apa...
Flink Forward Berlin 2017: Jörg Schad, Till Rohrmann - Apache Flink meets Apa...Flink Forward Berlin 2017: Jörg Schad, Till Rohrmann - Apache Flink meets Apa...
Flink Forward Berlin 2017: Jörg Schad, Till Rohrmann - Apache Flink meets Apa...
 
A Practical Guide to Selecting a Stream Processing Technology
A Practical Guide to Selecting a Stream Processing Technology A Practical Guide to Selecting a Stream Processing Technology
A Practical Guide to Selecting a Stream Processing Technology
 
Deploying Confluent Platform for Production
Deploying Confluent Platform for ProductionDeploying Confluent Platform for Production
Deploying Confluent Platform for Production
 
Decoupling Decisions with Apache Kafka
Decoupling Decisions with Apache KafkaDecoupling Decisions with Apache Kafka
Decoupling Decisions with Apache Kafka
 
Extending the Yahoo Streaming Benchmark + MapR Benchmarks
Extending the Yahoo Streaming Benchmark + MapR BenchmarksExtending the Yahoo Streaming Benchmark + MapR Benchmarks
Extending the Yahoo Streaming Benchmark + MapR Benchmarks
 
Event Sourcing, Stream Processing and Serverless (Benjamin Stopford, Confluen...
Event Sourcing, Stream Processing and Serverless (Benjamin Stopford, Confluen...Event Sourcing, Stream Processing and Serverless (Benjamin Stopford, Confluen...
Event Sourcing, Stream Processing and Serverless (Benjamin Stopford, Confluen...
 
Ted Dunning - Keynote: How Can We Take Flink Forward?
Ted Dunning -  Keynote: How Can We Take Flink Forward?Ted Dunning -  Keynote: How Can We Take Flink Forward?
Ted Dunning - Keynote: How Can We Take Flink Forward?
 

Similar to Seamless database migration case study - from Firebase real-time database to PostgreSQL

Engineering Machine Learning Data Pipelines Series: Streaming New Data as It ...
Engineering Machine Learning Data Pipelines Series: Streaming New Data as It ...Engineering Machine Learning Data Pipelines Series: Streaming New Data as It ...
Engineering Machine Learning Data Pipelines Series: Streaming New Data as It ...
Precisely
 
Five Workload-to-Cloud Migration Methods
Five Workload-to-Cloud Migration MethodsFive Workload-to-Cloud Migration Methods
Five Workload-to-Cloud Migration Methods
Peak 10
 
Data at Scale - Michael Peacock, Cloud Connect 2012
Data at Scale - Michael Peacock, Cloud Connect 2012Data at Scale - Michael Peacock, Cloud Connect 2012
Data at Scale - Michael Peacock, Cloud Connect 2012
Michael Peacock
 
Infrastructure Strategy
Infrastructure StrategyInfrastructure Strategy
Infrastructure Strategy
Robert Jones
 
RedisConf18 - Remote Monitoring & Controlling Scienific Instruments
RedisConf18 - Remote Monitoring & Controlling Scienific InstrumentsRedisConf18 - Remote Monitoring & Controlling Scienific Instruments
RedisConf18 - Remote Monitoring & Controlling Scienific Instruments
Redis Labs
 

Similar to Seamless database migration case study - from Firebase real-time database to PostgreSQL (20)

DC Migration and Hadoop Scale For Big Billion Days
DC Migration and Hadoop Scale For Big Billion DaysDC Migration and Hadoop Scale For Big Billion Days
DC Migration and Hadoop Scale For Big Billion Days
 
Best Practices: Migrating a Postgres Production Database to the Cloud
Best Practices: Migrating a Postgres Production Database to the CloudBest Practices: Migrating a Postgres Production Database to the Cloud
Best Practices: Migrating a Postgres Production Database to the Cloud
 
Always On - Zero Downtime releases
Always On - Zero Downtime releasesAlways On - Zero Downtime releases
Always On - Zero Downtime releases
 
Engineering Machine Learning Data Pipelines Series: Streaming New Data as It ...
Engineering Machine Learning Data Pipelines Series: Streaming New Data as It ...Engineering Machine Learning Data Pipelines Series: Streaming New Data as It ...
Engineering Machine Learning Data Pipelines Series: Streaming New Data as It ...
 
Five Workload-to-Cloud Migration Methods
Five Workload-to-Cloud Migration MethodsFive Workload-to-Cloud Migration Methods
Five Workload-to-Cloud Migration Methods
 
Artur Borycki - Beyond Lambda - how to get from logical to physical - code.ta...
Artur Borycki - Beyond Lambda - how to get from logical to physical - code.ta...Artur Borycki - Beyond Lambda - how to get from logical to physical - code.ta...
Artur Borycki - Beyond Lambda - how to get from logical to physical - code.ta...
 
Kinesis @ lyft
Kinesis @ lyftKinesis @ lyft
Kinesis @ lyft
 
Keepin’ It Real(-Time) With Nadine Farah | Current 2022
Keepin’ It Real(-Time) With Nadine Farah | Current 2022Keepin’ It Real(-Time) With Nadine Farah | Current 2022
Keepin’ It Real(-Time) With Nadine Farah | Current 2022
 
Guide to Application Performance: Planning to Continued Optimization
Guide to Application Performance: Planning to Continued OptimizationGuide to Application Performance: Planning to Continued Optimization
Guide to Application Performance: Planning to Continued Optimization
 
Distributed Kafka Architecture Taboola Scale
Distributed Kafka Architecture Taboola ScaleDistributed Kafka Architecture Taboola Scale
Distributed Kafka Architecture Taboola Scale
 
Sap migration to cloud
Sap migration to cloudSap migration to cloud
Sap migration to cloud
 
Tuning Java Driver for Apache Cassandra
Tuning Java Driver for Apache CassandraTuning Java Driver for Apache Cassandra
Tuning Java Driver for Apache Cassandra
 
2014 09-12 lambda-architecture-at-indix
2014 09-12 lambda-architecture-at-indix2014 09-12 lambda-architecture-at-indix
2014 09-12 lambda-architecture-at-indix
 
Data at Scale - Michael Peacock, Cloud Connect 2012
Data at Scale - Michael Peacock, Cloud Connect 2012Data at Scale - Michael Peacock, Cloud Connect 2012
Data at Scale - Michael Peacock, Cloud Connect 2012
 
Enabling big data & AI workloads on the object store at DBS
Enabling big data & AI workloads on the object store at DBS Enabling big data & AI workloads on the object store at DBS
Enabling big data & AI workloads on the object store at DBS
 
Mainframe Application Testing both With and Without Live Data
Mainframe Application Testing both With and Without Live DataMainframe Application Testing both With and Without Live Data
Mainframe Application Testing both With and Without Live Data
 
Druid @ branch
Druid @ branch Druid @ branch
Druid @ branch
 
Infrastructure Strategy
Infrastructure StrategyInfrastructure Strategy
Infrastructure Strategy
 
RedisConf18 - Remote Monitoring & Controlling Scienific Instruments
RedisConf18 - Remote Monitoring & Controlling Scienific InstrumentsRedisConf18 - Remote Monitoring & Controlling Scienific Instruments
RedisConf18 - Remote Monitoring & Controlling Scienific Instruments
 
Building Modern Digital Services on Scalable Private Government Infrastructur...
Building Modern Digital Services on Scalable Private Government Infrastructur...Building Modern Digital Services on Scalable Private Government Infrastructur...
Building Modern Digital Services on Scalable Private Government Infrastructur...
 

Recently uploaded

DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
MayuraD1
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
Epec Engineered Technologies
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
ssuser89054b
 
Digital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxDigital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptx
pritamlangde
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Kandungan 087776558899
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
HenryBriggs2
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
mphochane1998
 

Recently uploaded (20)

DeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakesDeepFakes presentation : brief idea of DeepFakes
DeepFakes presentation : brief idea of DeepFakes
 
Standard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power PlayStandard vs Custom Battery Packs - Decoding the Power Play
Standard vs Custom Battery Packs - Decoding the Power Play
 
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKARHAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
HAND TOOLS USED AT ELECTRONICS WORK PRESENTED BY KOUSTAV SARKAR
 
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
 
Digital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptxDigital Communication Essentials: DPCM, DM, and ADM .pptx
Digital Communication Essentials: DPCM, DM, and ADM .pptx
 
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak HamilCara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
Cara Menggugurkan Sperma Yang Masuk Rahim Biyar Tidak Hamil
 
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx
457503602-5-Gas-Well-Testing-and-Analysis-pptx.pptx
 
Learn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic MarksLearn the concepts of Thermodynamics on Magic Marks
Learn the concepts of Thermodynamics on Magic Marks
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
scipt v1.pptxcxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx...
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
 
Introduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdfIntroduction to Data Visualization,Matplotlib.pdf
Introduction to Data Visualization,Matplotlib.pdf
 
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
COST-EFFETIVE  and Energy Efficient BUILDINGS ptxCOST-EFFETIVE  and Energy Efficient BUILDINGS ptx
COST-EFFETIVE and Energy Efficient BUILDINGS ptx
 
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
Bhubaneswar🌹Call Girls Bhubaneswar ❤Komal 9777949614 💟 Full Trusted CALL GIRL...
 
Design For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the startDesign For Accessibility: Getting it right from the start
Design For Accessibility: Getting it right from the start
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
 
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best ServiceTamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
Tamil Call Girls Bhayandar WhatsApp +91-9930687706, Best Service
 
💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...
💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...
💚Trustworthy Call Girls Pune Call Girls Service Just Call 🍑👄6378878445 🍑👄 Top...
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 

Seamless database migration case study - from Firebase real-time database to PostgreSQL

  • 1. Case Study: Seamless database migration - from Firebase real-time database to PostgreSQL 8th Oct, 2020 Software Development Manager Pin-Ying Tu spirit@inline.tw
  • 2. / 23 About • High-scale software engineer • US$1M+ spent on cloud • Hiring Manager :-) • Ph.D. NTUT • 8 years software engineering experience • inline Case Study: Seamless database migration - from Firebase real-time database to PostgreSQL 1 github.com/dbi1463
  • 3. / 23 inline services 1/2 • Start from automated queueing – Realtime status update • Booking management – Multiple sources – Full capcaity management Case Study: Seamless database migration - from Firebase real-time database to PostgreSQL 2
  • 4. / 23 inline services 2/2 • CRM – Actionable insights – Campaign SMS – Survey and coupon • Takeout and delivery and more – Menu management – Integration with multiple delivery partners Case Study: Seamless database migration - from Firebase real-time database to PostgreSQL 3
  • 5. / 23 We are growing, quickly Case Study: Seamless database migration - from Firebase real-time database to PostgreSQL 4
  • 6. / 23 Why did we choose Firebase real-time database? • Less backend work • Real-time data synchronization is a very important feature Case Study: Seamless database migration - from Firebase real-time database to PostgreSQL 5
  • 7. / 23 Sharding for growth Case Study: Seamless database migration - from Firebase real-time database to PostgreSQL main Shard 1 Shard 2 Cust 1 Cust 2 Cust 3 Cust 4 Without our own API server, clients need to be aware of which shard to connect Moving data around shards takes time and money Shards got slow again when data growth Script to move data from master to the new shard and deploy functions to each shard 6
  • 8. / 23 New synchronization mechanism 1/2 • Minimize memory usage in client-side endpoints – Firebase iOS SDK consume huge memory if off-line mode is enabled – Firebase iOS SDK read/write performance become very bad when the network environment is not good • We want a faster and smaller memory footprint sync method – Data synchronization between multiple devices • 95% reservations should be synchronized in 5 seconds – Support off-line first • Still provide good user experience (do not block user operations) • Can not lose any reservation even the network environment is not good –Seamless • No service down time • The restaurants are not aware of the changes Case Study: Seamless database migration - from Firebase real-time database to PostgreSQL 7
  • 9. / 23 New synchronization mechanism 2/2 Case Study: Seamless database migration - from Firebase real-time database to PostgreSQL Persistent, ordered, and parallel requests Three long polling APIs for better UX experience Trigger cloud functions Publish a sync event to PubSub Background jobs receive sync events Background jobs handle the out of order issue and write data to Elasticsearch Background jobs touch Redis to notify hooked long polling requests Monitor the pending writes requests Monitor the cost distribution Unsync reporter 8
  • 10. / 23 Decouple Firebase SDK, finally Case Study: Seamless database migration - from Firebase real-time database to PostgreSQL +request(in path) : InvokableRestRequest RestClientImpl +request(in path) : InvokableRestRequest <<interface>> RestClient +query(in name , in value) +where(in name, in value) +get(in handler : ResponseHandler) +post(in handler : ResponseHandler) +put(in handler : ResponseHandler) +delete(in handler : ResponseHandler) +getPlainText(in handler : ResponseHandler) +invoke(in method : string, in body : object, in handler : ResponseHandler) InvokableRestRequestImpl InvokableRestRequest +create(in reservation) MutableReservationFirebaseWebService <<interface>> MutableReservationWebService +create(in reservation) MutableReservationRestfulWebService +get() : MutableReservationWebServiceProvider MutableReservationWebServiceProvider +add(in request : SerializableRequest) -persist(in request : SerializableRequest) -remove(in request : SerializableRequest) +runNext() SerializableRestRequestQueue +invoke() +init() -id : string -timestamp : long -completedURL : string -httpHeaders : [string: string] -body : object -handler : ResponseHandler SerializableRequest Codeable Only serialize the write operations, i.e., POST, PUT, and DELETE The requests must be executed in order Move the original Firebase implementation to here 9
  • 11. / 23 Performance improvement Case Study: Seamless database migration - from Firebase real-time database to PostgreSQL Off-line to online Bad network Create and edit n reservations and wait all reservations were synchronized to all devices X: time Y: pending writes per second Blue: Firebase SDK Red: Firebase REST API Normal network 10
  • 12. / 23 The device sync dashboard Case Study: Seamless database migration - from Firebase real-time database to PostgreSQL Device-to-device cost by location Upload latency by location Device-to-device cost by day 11
  • 13. / 23 So far so good, but we want better • Scaling goals we want to achieve – 99.99% availability of customer-facing services, with: – Fast and flexible queries • Like other database, without index the query is very slow • Firebase real-time database query only supports one index • Need to build the indices programmatically by ourselves – Fully managed DB shard and persistence migrations • Firebase team migrate the instances without any notification • We can not schedule the migration • During the time to rebuild in-memory indices after migration, all accesses to Firebase database are queued – Able to scale workers horizontally in one AZ and across Azs • Firebase cloud functions have 1,000 deployment quota Case Study: Seamless database migration - from Firebase real-time database to PostgreSQL As a result, we decide to migrate our main database. 12
  • 14. / 23 Architecture Evolution • Current architecture • New architecture Case Study: Seamless database migration - from Firebase real-time database to PostgreSQL Persistent, ordered, and parallel requests inline APIs write to PostgreSQL and touch Redis to notify the subscribed WebSocket handlers Devices receive events through WebSocket with some APIs to improve UX experience Background jobs to perform the functionalities of the original cloud functions 13
  • 15. / 23 Phase 0 – Performance evaluation • Make sure PostgreSQL can meet our performance goals – 50 M data set – Maximum query time • Current 36ms avg Goal: 200 rows in 30 ms – Queries per second • Current: 117/sec sustained Goal (5x): 585/sec sustained – Inserts/Updates per second • Current: 40/sec sustained Goal (5x): 200/sec sustained Case Study: Seamless database migration - from Firebase real-time database to PostgreSQL 14 Connection pool
  • 16. / 23 Phase 1 – Sync new reservations to PostgreSQL • Not breaking any existing system – Still a few restaurants use the version before long polling – Not every restaurant upgrade app frequently • Use feature toggle to control the switch between two methods Case Study: Seamless database migration - from Firebase real-time database to PostgreSQL 15
  • 17. / 23 Phase 2 – Make sure WebSocket works • Use feature toggle (remote control) to switch between WebSocket and long polling Case Study: Seamless database migration - from Firebase real-time database to PostgreSQL 16
  • 18. / 23 Phase 3 – Copy old reservations to PostgreSQL • Controllable copy scopes – By brand or by shard Case Study: Seamless database migration - from Firebase real-time database to PostgreSQL 17
  • 19. / 23 Phase 4 – Move cloud functions • Totally 31 cloud functions moved – Use feature toggle to enable/disable the cloud functions Case Study: Seamless database migration - from Firebase real-time database to PostgreSQL 18
  • 20. / 23 Phase 5 – inline APIs • Implement the new inline APIs and clients adopt APIs – Also write back to Firebase • Fully tested with all combination on beta – Firebase REST API – inline API – WebSocket – Long polling Case Study: Seamless database migration - from Firebase real-time database to PostgreSQL 19
  • 21. / 23 Phase 6 – controlled roll out • Planned roll out – Start to migrate a company that is willing to try new method – Start to migrate shard by shard until all shards migrated Case Study: Seamless database migration - from Firebase real-time database to PostgreSQL 20
  • 22. / 23 Phase 7 - Remove Firebase dependency • After migrate all shards and companies, trigger the force upgrade notification • Remove Firebase dependency from inline APIs Case Study: Seamless database migration - from Firebase real-time database to PostgreSQL 21
  • 23. / 23 Lession learned 1/2 • Abstraction layer – Try to minimize vendor lock-in for fundamentals of your system – Even if it costs more in time during the first implementation • Cost estimation – Don't forget to turn off the load generator – Set up a spending rate monitor • Planning is important – Help design thinking • Testing is important – Unit testing, end-to-end testing, and load testing all help us not breaking anything important to our customers depend on Case Study: Seamless database migration - from Firebase real-time database to PostgreSQL 22
  • 24. / 23 Lession learned 2/2 • Always contact the cloud service support team – They have more than the public information and wouldn’t let you know if you did not ask • Choose cloud service platform carefully – Do some evaluation for your needs before choosing a cloud service platform • Data synchronization is extreme difficult – Do not build your own synchronization unless the current solution can not meet your needs Case Study: Seamless database migration - from Firebase real-time database to PostgreSQL Any question? 23

Editor's Notes

  1. AND unless you have plenty of time, and can deal effectively with complex GCP/AWS configurations