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

Building an offline-first service

Building an offline-first service

We look at one approach to build offline-first mobile applications using React Native, Redux, Scala, Akka persistence and Event-sourcing, CQRS concepts.

Akos Krivachy

January 13, 2017
Tweet

More Decks by Akos Krivachy

Other Decks in Programming

Transcript

  1. Issue: out-of-sync local cache • GET /users/123 followerCount: 5 •

    Go offline • Navigate to followers screen: Only 4
  2. Issue: truly offline - is everything local? • Have x

    resources: • /users, /posts, /posts/comments, /feed, /profile, etc. • How do you refresh all your data when online? • Possible solutions: E-Tags/If-Modified- Since, only get changes/diffs
  3. Command Actor • One Actor per entity (aggregate root) •

    State is in memory • Validate commands • Persist events
  4. Event Payload final case class ClientEventJsonEnvelope( eventId: EventId, sourceCommandId: CommandId,

    sequenceId: Long, `type`: String, timestamp: DateTime, payload: JsValue)
  5. Schema CREATE TABLE IF NOT EXISTS journal ( ordering SERIAL,

    persistence_id VARCHAR(255) NOT NULL, sequence_number BIGINT NOT NULL, deleted BOOLEAN DEFAULT FALSE, tags VARCHAR(255) DEFAULT NULL, message BLOB NOT NULL, PRIMARY KEY(persistence_id, sequence_number) );
  6. Advantages App experience much better Rock solid API Backend availability

    requirements lower Free audit log, immutable events
  7. Disadvantages More engineering New way of thinking: how will this

    work offline? App can’t store everything (infeasible amount of data) UX needs to be extremely good
  8. Other options Firebase, PouchDB, Realm, Horizon, Rethink Make it work

    with REST – not impossible WebSockets for protocol GraphQL (view side)
  9. Resources • Immutable User Interfaces, Lee Byron https://vimeo.com/166790294 • CQRS,

    not just for server systems, Greg Young https://skillsmatter.com/skillscasts/1980-cqrs-not-just-for-server- systems • http://offlinefirst.org/ https://github.com/offlinefirst/research/blob/master/links.md