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

Streaming Commutative Replicated Data

Streaming Commutative Replicated Data

A streaming CRDT demo and lightning talk at DenverJS May 3 2013. https://github.com/mbrevoort/CRDTDenverJs

7071119714e1a32441aca0c336657d3e?s=128

Mike Brevoort

May 03, 2013
Tweet

Transcript

  1. STREAMING COMMUTATIVE REPLICATED DATA 2 MAY 2013 / Mike Brevoort

    @mbrevoort
  2. WHAT IS A CRDT? CONVERGENT OR COMMUTATIVE REPLICATED DATA TYPE

    A data type designed so that operations on it between replicas commute and produce the same result independant of the order in which they are applied.
  3. EVENTUALLY CONSISTENT

  4. NOT BASED ON CONSENSUS

  5. STATE-BASED VS OPERATION-BASED

  6. TOLERANT TO NETWORK LATENCY, FAULTS AND INTERUPTION

  7. PERFECT FOR COLLABORATIVE, DISTRIBUTED AND PEER TO PEER USE CASES

  8. THE SCIENCE http://hal.upmc.fr/docs/00/55/55/88/PDF/techreport.pdf

  9. A JAVASCRIPT IMPLEMENTATION as a stream interface https://github.com/dominictarr/crdt

  10. A SIMPLE SAMPLE / / s e r v e

    r v a r n e t = r e q u i r e ( ' n e t ' ) v a r D o c = r e q u i r e ( ' c r d t ' ) . D o c v a r A = n e w D o c ( ) n e t . c r e a t e S e r v e r ( f u n c t i o n ( s t r e a m ) { s t r e a m . p i p e ( A . c r e a t e S t r e a m ( ) ) . p i p e ( s t r e a m ) } ) / / c l i e n t v a r n e t = r e q u i r e ( ' n e t ' ) v a r D o c = r e q u i r e ( ' c r d t ' ) . D o c v a r A = n e w D o c ( ) v a r s t r e a m ( s t r e a m = n e t . c o n n e c t ( ) ) . p i p e ( A . c r e a t e S t r e a m ( ) ) . p i p e ( s t r e a m )
  11. TO THE BROWSER! / / s e r v e

    r v a r b o a r d = n e w c r d t . D o c ( ) / / s h o e i s a s t r e a m s w r a p p e r a r o u n d s o c k j s ( w e b s o c k e t s ) s h o e ( f u n c t i o n ( s o c k ) { v a r m x ; s o c k . p i p e ( m x = n e w M u x D e m u x ( f u n c t i o n ( s ) { s . p i p e ( b o a r d . c r e a t e S t r e a m ( ) ) . p i p e ( s ) } ) ) . p i p e ( s o c k ) } ) . i n s t a l l ( s e r v e r . l i s t e n ( 3 0 0 0 ) , ' / s h o e ' ) / / c l i e n t v a r b o a r d = n e w c r d t . D o c ( ) v a r s t r e a m = s h o e ( ' / s h o e ' ) v a r m x = M u x D e m u x ( ) s t r e a m . p i p e ( m x ) . p i p e ( s t r e a m ) v a r d s = b o a r d . c r e a t e S t r e a m ( ) d s . p i p e ( m x . c r e a t e S t r e a m ( { t y p e : ' b o a r d ' } ) ) . p i p e ( d s )
  12. DEMO!

  13. 0 0 0 0 0 0 1 0 0 1

    0 1 0 1 0 0 0 0 1 0 0 1 1 0 0 1 0 0 0 9 7 0 1 0 0 0 0 1 0 0 2 0 0 0 0 0 0 0 0 0 0 1 0 0 1 1 0 1 0 0 1 7 6 0 1 0 0 0 0 0 0 0 0 1 0 1 0 0 1 0 1 1 1 0 0 0 1 0 1 0 1 1 1 0 1 0 0 0 1 6 CONNECTED disconnect Reset 0 0 0 0 0 0 1 0 0 1 0 1 0 1 0 0 0 0 1 0 0 1 1 0 0 1 0 0 0 9 7 0 1 0 0 0 0 1 0 0 2 0 0 0 0 0 0 0 0 0 0 1 0 0 1 1 0 1 0 0 1 7 6 0 1 0 0 0 0 0 0 0 0 1 0 1 0 0 1 0 1 1 1 0 0 0 1 0 1 0 1 1 1 0 1 0 0 0 1 6 CONNECTED disconnect Reset
  14. THANKS! Mike Brevoort @mbrevoort https://github.com/mbrevoort/CRDTDenverJs