Composing side effects in Clojure

35a1675bf5d2da0e2d60063d2a22f352?s=47 kapil
August 31, 2019

Composing side effects in Clojure

We always end up in a situation where we need to do a bunch of side effects on a user action. This is simple as long as the side effects don’t depend on each other. Errors and unhappy paths make it even harder. The talk presents an approach that tries to solve these problems.

35a1675bf5d2da0e2d60063d2a22f352?s=128

kapil

August 31, 2019
Tweet

Transcript

  1. Handling and Composing side effects In Clojure Or how to

    avoid mud-balls By Kapil Reddy
  2. Principal Engineer @ Helpshift Clojure Distributed Systems Music Graphic novels

    Football Film and Theatre
  3. None
  4. Scale • 165000 Requests per Second • @50 ms Response

    time • ~400GB data transfer every hour • 1000+ VMs deployed at peak
  5. Journey of a Clojure codebase

  6. A simple web app

  7. POST /favourites/ Add a song to favourites

  8. Request -> Server -> Response

  9. Request -> Server -> Response

  10. Server Req -> Handler -> Resp

  11. None
  12. None
  13. None
  14. None
  15. None
  16. None
  17. None
  18. None
  19. None
  20. None
  21. {}

  22. None
  23. http://blog.fogus.me/2010/09/28/thrush-in-clojure-redux/

  24. None
  25. None
  26. None
  27. None
  28. None
  29. None
  30. None
  31. None
  32. None
  33. None
  34. None
  35. None
  36. None
  37. Problems with thrush for side effects • Overlapping keys

  38. None
  39. Problems with thrush for side effects • Overlapping keys •

    Shape of data gets complex
  40. None
  41. Failures !!!

  42. None
  43. None
  44. None
  45. Problems with thrush for side effects • Overlapping keys •

    Shape of data gets complex • Handling complex error scenarios
  46. Can we do better?

  47. None
  48. None
  49. None
  50. None
  51. Great, how do use it?

  52. Solution!?

  53. Shinri

  54. None
  55. None
  56. None
  57. None
  58. None
  59. None
  60. None
  61. Problems with thrush for side effects • Overlapping keys •

    Shape of data gets complex • Can’t handle complex failure scenarios
  62. Problems with thrush for side effects • Overlapping keys •

    Shape of data gets complex • Can’t handle complex failure scenarios
  63. None
  64. None
  65. None
  66. None
  67. None
  68. None
  69. None
  70. Problems with thrush for side effects • Overlapping keys •

    Shape of data gets complex • Can’t handle complex failure scenarios
  71. None
  72. None
  73. None
  74. None
  75. None
  76. None
  77. None
  78. Order is implicit

  79. None
  80. None
  81. Self documenting

  82. None
  83. Execution and policy are separate

  84. Parallel execution

  85. None
  86. None
  87. None
  88. Future • core.async support • clojure.spec support

  89. Alternatives • Prismatic Plumbing • Function lenses

  90. Conclusions • Writing complex side effects code can be tricky

    • Thrush is not a good abstraction for side effects • Graphs are a great way to represent multiple side effects / computations • Defining APIs is simple in Clojure • Libraries like Shinri and Prismatic Plumbing can help
  91. Fin