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

The way of truly serverless application

miup
November 21, 2017

The way of truly serverless application

Firebase.yebisu #1

miup

November 21, 2017
Tweet

More Decks by miup

Other Decks in Programming

Transcript

  1. The way of 
 truly serverless application Firebase.Yebisu #1

  2. ࣗݾ঺հ ࡾӜ ࿨໵ (ID: miup) • ࠓ೥৽ଔͰೖࣾ (ࠃ಺ࣄۀ։ൃ෦ॴଐ) • ݄̑ͷ഑ଐ͔Β

    Firebase Λ৮Γ࢝Ίͨ • iOS ΞϓϦ͸̐೥͘Β͍ॻ͍͍ͯΔ
  3. Truly Serverless?

  4. Truly Serverless • ج൫͸͢΂ͯ֎෦ BaaS, SaaS ʹґଘ • ॻ͘ͷ͸ΫϥΠΞϯτΞϓϦέʔγϣϯͱͦ ΕΒαʔϏεͱͷ࿈ܞͷΈ

  5. Firebase Ͱे෼Ͱ͸ʁ

  6. Firebase ͷ೉఺ • DB ͷΫΤϦ͕ѹ౗తʹऑ͍ • FireStore Ͱ΋ෳࡶͳΫΤϦ͸·͔͚ͩͳ͍

  7. ΫΤϦ͕ऑ͍ͱʁ • ΫϥΠΞϯταΠυδϣΠϯ͕ඞཁ • ඇಉظ͕ॏͳͬͯͭΒ͍ • όάͷԹচ • ηϧͷߴ͞ܭࢉͱ͔͏·͍͔͘ͳ͍ https://qiita.com/miuP/items/ce3a3888d5411d2f8e70

  8. Solution • Realm • ֎෦ݕࡧΤϯδϯΛ࢖͏

  9. Algolia Search • શจݕࡧΤϯδϯ • ೔ຊޠରԠ • FireStore ͷશจݕࡧͷͱ͜ΖͰνϣϩͬͱ৮ ΕΒΕ͍ͯΔ


    https://firebase.google.com/docs/firestore/solutions/search

  10. ࿈ܞ • ॻ͖ࠐΈݖݶͷ API Key ΛΫϥΠΞϯτͰ࣋ ͯͳ͍ • όοΫΤϯυΞϓϦέʔγϣϯ͕લఏ

  11. Archtecture #BDLFOE
 "QQMJDBUJPO 'JSFCBTF &YUFSOBM4FSWJDF .PCJMF"QQ : Read : Write

  12. Firebase ͚ͩͰͳΜͱ͔͍ͨ͠

  13. CloudFunctions • HTTP ΍ DB ΁ͷมߋΛϑοΫʹಈ࡞͢Δ Node.js ؀ڥ • ΋ͪΖΜ

    TypeScript Ͱ΋ॻ͚Δ • ֎෦ API Λୟ͚Δ • Push ௨஌ૹΕΔ
  14. Architecture 'JSFCBTF
 
 
 &YUFSOBM
 4FSWJDF .PCJMF"QQ : Read :

    Write $' %#
  15. Write 'JSFCBTF
 
 
 $' %# .PCJMF"QQ &YUFSOBM
 4FSWJDF callback

    Firebase Cloud Messaging
 Silent Push
  16. Read 'JSFCBTF
 
 
 &YUFSOBM
 4FSWJDF .PCJMF"QQ %# Observe Realtime

    Value Get main Data
  17. ίʔυྫ

  18. Algent • [WIP] • Algolia ͷΫϥΠΞϯτͷ wrapper • Decodable ͳܕΛ

    Response Ͱࢦఆ • ˑˑˑˑˑ
  19. Write functions.database.ref(‘path/to/user/{userID}').onCreate(async event => { let userID = event.params!.userID let

    firUser = await admin.database() .ref(`path/to/user/${userID}`) .once(‘value').then(snap => snap.val()) let userIndex = algolia.initIndex('user') let user = new User(userID, firUser) return userIndex.addObject(user) // send FCM for callback }) ref: https://qiita.com/star__hoshi/items/6ee9d1413a34ca5849eb
  20. Request struct AlgoliaFeedRequest: AlgoliaRequestProtocol { typealias HitType = Algolia.Feed var

    indexName: String { return "feed" } var query: AlgentQuery { let query = AlgentQuery() return query } }
  21. Read // search from algolia using Algent // Result<Response<Response<Request.HitType>, Error>

    Algent.shared.search(request: AlgoliaFeedRequest()) Firebase.Post.databaseRef .child(feed.objectID) .child(“likes/count") .observe(.value) { [weak self] snapshot in if snapshot.exists() { self?.likeCountString.value = "\(snapshot.value as? Int)" } else { self?.likeCountString.value = "0" } }
  22. Sample • SNS ͬΆ͍΍ͭ • Feed ͱ User ͸ Algolia

    ͔Βݕࡧ • ͍͍Ͷʂ΍౤ߘ਺ͳͲͷมಈ͢Δ஋ͷΈΛ RealtimeDB͔ΒObserve • Silent Push ͔Βߋ৽͸ະ࣮૷
  23. σϞ
 https://github.com/miuP/AlgoliaFirebaseSample

  24. ·ͱΊ • Truly Serverless • Firebase ͰͰ͖ͳ͍͜ͱ͸ແཧͤͣผͷࡦΛ ࿅Δ • ֎෦αʔϏεͱͷ࿈ܞ΋໰୊ͳ͍

    ϞόΠϧΤϯδχΞ͚ͩͰαʔϏε࡞Δͧʙʂ
  25. Q&A