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

Optimistic UI with Logux & Ruby

Optimistic UI with Logux & Ruby

Logux is the new way of synchronisation between client and server, which provides many features for modern web out of the box: live updates, optimistic UI, Offline-first.

Introduce logux_rails Ruby gem for easy integration Logux into existing Ruby/Rails backend.

Salahutdinov Dmitry

April 06, 2019
Tweet

More Decks by Salahutdinov Dmitry

Other Decks in Programming

Transcript

  1. 4

  2. 11

  3. Story By Denys Mishunov Original photo Why to loose time

    if you know how pubs work? Optimistic UI 12
  4. !15

  5. !16

  6. Handing network errors In case the UI already was updated,

    but request failed 23 Client Logux server Network problems Name: ‘new’ Changes are applied before the request Name: ‘new’
  7. Uses Web Sockets For bidirectional messaging and live updates Live

    updates! build collaborative tools (like G oogle D ocs) !36 WebSockets Client Logux server
  8. Tracks the connection Defer sending until connection restores Support of

    Offline-mode! !41 Ping Pong Ping Synchonization… ……… Client Logux server Periodical pings
  9. Lack of universal clock Time is hard in distributed systems

    !42 Connect Round trip time serverTime - localTime + roundTripTime / 2 Synchronize eventTime = localTime + timeShift Logux server Logux server Client Client
  10. Helps to merge conflicts By handling event time/order Logux is

    CRDT ready! !44 Changes Are not applied ❌ Clients Logux server Last win!
  11. HTTP backend Forwards events from Logux-server over HTTP !49 HTTP

    protocol WSS WSS Backend Logux server Clients Forward events Backward synchronisation
  12. Channels Logux maintains channels natively !54 Subscribe Subscribed Sync subscribed

    Initial state Sync initial state Send data Broadcast data Backend Logux Server Client
  13. Channel initialisation Send “initial state” data to the subscribed client

    !55 Initial state Sync initial state Backend Logux Server Client
  14. Backward sync Triggers event on backend, and synchronises with clients

    Broadcast Backend Logux Server Subscribed clients
  15. Undo !59 Rename: ‘new name’ Subscribed Undo: ‘rename’ Backend Logux

    Server Client Rename: ‘new name’ Error Undo: ‘rename’ New name Old name ❌
  16. Optimistic update With automatic synchronization !63 Subscribe to ‘project/123’ Backend

    Logux Server Client Client Subscribe to ‘project/123’ ‘new name’ to ‘project/123’ ‘new name’ to ‘project/123’ ‘new name’ to ‘project/123’ Subscribe to ‘project/123’ Subscribe to ‘project/123’ New name New name New name
  17. !64 Chat (live updates) Chat (live updates) Chat (live updates)

    Comment Sync Client Client Logux Server Comment Sync
  18. Backward sync Centralized UI update initiated by from backend !66

    Actual currency rate http://amplifr.com Backend
  19. Send back to client From the server regular background task

    !67 Subscribe to ‘prices’ Backend Logux Server Client Client Subscribe to ‘prices’ update currency rate update currency rate update currency rate Subscribe to ‘prices’ Subscribe to ‘prices’ Rake Task
  20. • Built-in optimistic UI will improve UI performance. • Built-in

    live updates allow to build collaborative tools (like Google Docs). • Built-in offline-first will improve UX on unstable connection.
 It is useful from next billion users to New York subway. • Compatible with modern stack: Redux API, works with Ruby backend Wrap up !68