Ideal State • Data from Firebase ≠ Data in app -> Need translation • Easy to replace from API to Firebase -> I/F is same as API, then want to replace DAO
protocol Entity: Codable {} struct UserEntity: Entity { let name: String } struct LinkEntity: Entity { let title: String let href: URL let submitted: String } struct CommentEntity: Entity { let link: String let body: String let author: String } Entity Entity Data Access Data Access Interactor Model Presenter View
Data Access struct UserRepository { let dataStore: LinkDataStore func get(userId: String) -> Single { return dataStore.get(key: userId) } } struct UserDataStore { let provider = DataProvider.shared func get(key: String) -> Single { return provider.getUser(key: key) } } I/F for data access Implementation for data access Entity Data Access Data Access Interactor Model Presenter View
Pros/Cons • Must have join logic in client side • Need more money $ to build in some case • Data cache system doesn’t suit for your app in some case • Sorting and Query are hard to use • Scaling requires sharding (100,000 concurrent connections & 1,000 writes/sec.) Cons
Pros/Cons • Must have join logic in client side • Need more money $ to build in some case • Data cache system doesn’t suit for your app in some case • Sorting and Query are hard to use • Scaling requires sharding (100,000 concurrent connections & 1,000 writes/sec.) Cons %
• Stores data in documents organized in collections • Sending data with protobuf, which have more types • Introduced reference type, so requires less denormalization and data flattening • Indexed queries with compound sorting and filtering Cloud Firestore
Recap • Serverless architecture ( mBaaS / SaaS and etc. ) is also effective to use on native apps • API server can be replaced by Firebase Database / Cloud firestore in some case • Replaceable DAO and separate Entity and Model in app is important • With side effect, easy to test modules
References • Clean Code: A Handbook of Agile Software Craftsmanship by Robert C. Martin • https://firebase.google.com/docs/firestore/rtdb-vs-firestore • https://firebase.google.com/docs/firestore/firestore-for- rtdb • https://speakerdeck.com/bpyamasinn/api-wo-firebase- realtime-database-niyi-xing-siteqi-fu-itakoto-ver2