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

Stateful Apps with OTP

Stateful Apps with OTP

Maciej Kaszubowski

April 20, 2017
Tweet

More Decks by Maciej Kaszubowski

Other Decks in Programming

Transcript

  1. Stateful Apps
    with OTP
    Maciej Kaszubowski

    View Slide

  2. Realtime Apps
    with OTP
    Maciej Kaszubowski

    View Slide

  3. Background

    View Slide

  4. Http
    Server
    Client

    View Slide

  5. Architecture
    Server
    Mobile
    Mobile
    Kurento
    Mobile
    Websocket
    Websocket
    &
    REST
    WebRTC

    View Slide

  6. Challenges

    View Slide

  7. Async communication with
    Kurento

    View Slide

  8. Async communication with
    Clients

    View Slide

  9. Handling
    Concurrent Calls

    View Slide

  10. Deploys, migrations
    & Restarts

    View Slide

  11. A lot
    can go wrong

    View Slide

  12. A lot
    can go wrong
    &
    Errors are dangerous

    View Slide

  13. How to deal with this?

    View Slide

  14. init callback

    View Slide

  15. init callback

    View Slide

  16. init callback

    View Slide

  17. init callback

    View Slide

  18. init callback

    View Slide

  19. init callback

    View Slide

  20. Dealing with failures

    View Slide

  21. RoomServer

    View Slide

  22. RoomServer

    View Slide

  23. Let it
    FAIL

    View Slide

  24. Room
    Supervisor
    RoomServer

    View Slide

  25. Room
    Supervisor
    RoomServer

    View Slide

  26. Room
    Supervisor
    RoomServer

    View Slide

  27. After the restart,
    the state is gone

    View Slide

  28. Room
    Supervisor
    BackupServer RoomServer

    View Slide

  29. View Slide

  30. Room
    Supervisor
    BackupServer RoomServer

    View Slide

  31. View Slide

  32. View Slide

  33. Multiple calls

    View Slide

  34. Room
    Supervisor
    BackupServer RoomServer

    View Slide

  35. Common
    Room
    Supervisor
    Room
    Supervisor
    Backup
    Server
    Room
    Server
    Room
    Supervisor
    Backup
    Server
    Room
    Server

    View Slide

  36. Common
    Room
    Supervisor
    Room
    Supervisor
    Backup
    Server
    Room
    Server
    Room
    Supervisor
    Backup
    Server
    Room
    Server

    View Slide

  37. Common
    Room
    Supervisor
    Room
    Supervisor
    Backup
    Server
    Room
    Server
    Room
    Supervisor
    Backup
    Server
    Room
    Server

    View Slide

  38. Common
    Room
    Supervisor
    Room
    Supervisor
    Backup
    Server
    Room
    Server

    View Slide

  39. PubSub

    View Slide

  40. Status Updates
    Server
    Mobile Join
    Mobile Room status

    View Slide

  41. MyApp.Endpoint.broadcast(
    “room_id”, “update_status”, status
    )

    View Slide

  42. apps/
    |
    |—— domain/
    |—— web/

    View Slide

  43. Status Updates
    Server
    Mobile
    Mobile Subscribe
    Subscribe

    View Slide

  44. Status Updates
    Server
    Mobile
    Mobile
    Join

    View Slide

  45. Status Updates
    Server
    Mobile
    Mobile Status update
    Status update

    View Slide

  46. Status Updates

    View Slide

  47. Status Updates

    View Slide

  48. Status Updates

    View Slide

  49. Status Updates

    View Slide

  50. Status Updates

    View Slide

  51. Status Updates

    View Slide

  52. History

    View Slide

  53. History
    Server Call
    History
    Subscribe
    Status update

    View Slide

  54. History

    View Slide

  55. History

    View Slide

  56. History

    View Slide

  57. Conclusions

    View Slide

  58. Simpler system

    View Slide

  59. Testing is easy

    View Slide

  60. Changes are easy

    View Slide

  61. Great performance

    View Slide

  62. We should learn
    from the Erlang community

    View Slide

  63. A lot of fun!

    View Slide

  64. Thanks!

    View Slide