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

Mike Brevoort

May 03, 2013
Tweet

More Decks by Mike Brevoort

Other Decks in Technology

Transcript

  1. 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.
  2. 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 )
  3. 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 )
  4. 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