Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Firebase Realtime Database in production

Firebase Realtime Database in production

#GDG DevFest 2018 セッション7 Room C+D
Firebase Realtime Databaseを利用したチャットサービスの構築・運用をして得た知見をお伝えできればと思います。 パフォーマンスについて、障害に対してどう対応すべきか、フロントエンド側の知見等。

Transcript

  1. Agenda •  About AI Messenger •  What is Firebase • 

    Why choose Firebase Realtime Database •  Architecture of AI Messenger •  Dealing with problems •  How to manage incidents •  Future works
  2. 4 Architecture of AI Messenger PubSub Web Chat Cloud Load

    Balancer Operator Console Container Container Cloud BigTable Listening Firebase Listening Firebase Double Write to BigTable Write to Firebase Write new message Write new message Process message 1 3 5 AI 2 Immediately respond 202 Stack Driver
  3. Why write from server only? ׃ַ׃ •  ر٦ةך2ꅾ盖椚 •  ر٦ةךⴓ侔

    •  ꟦חAPI׾䮠׬ֿהדꥺ㹱ך然桦ָ♳ָ׷ הְֲرًٔحز׮֮׷ 荈ⴓך؟٦ؽأח嗚稊ָ䗳銲זךַծر٦ةو؎ؚٖ٦ءָّٝ 걼籕ח饯ֿ׷ךַ瘝׾ぶ㄂׃ג罋ִ׷䗳銲ָ֮׷ Architecture of AI Messenger
  4. Dealing with some problems ChatApp {"message": "hello" } 202 {"id":

    "afdajjje3jfd" } { "message": "hello", "id": "afdajjje3jfd" } Write Async Request Response Update view with dummy message wait 3s Replace with real value
  5. Dealing with some problems ChatApp {"message": "hello" } 202 {"id":

    "afdajjje3jfd" } { "message": "hello", "id": "afdajjje3jfd" } Update same property if value updated twice Request Response Resend message with id Now, we know message id
  6. Dealing with some problems /messages/afj34f0kfa/0afdajjje3jfd { "message": "hello" } /messages/afj34f0kfa/1afdajjje3jfd

    { "message": "hello", } /archive/afj34f0kfa Move closed conversation to archives to omit filtering /conversations/afj34f0kfa Messages are stored under conversation id and ordered unique message id to sorting with key
  7. How to manage incidents Observer Write value with 1s interval

    ChatApp Listening observer writing value If firebase is down, using rest. Listening message/conversation