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

Persistent Data Structures in System Design

Persistent Data Structures in System Design

Persistent data structures are a powerful tool in the functional programming toolbox, allowing us to work with changing data without sacrificing referential transparency. However the use of persistent data structures often stops with the program, the resulting code flung over the wall to be built and deployed in non-referentially transparent systems. In this talk we will see that it doesn't have to be this way and explore system designs that leverage the techniques of persistent data structures to recover referential transparency in the ever changing world of builds and deployments.

Adelbert Chang

January 09, 2018
Tweet

More Decks by Adelbert Chang

Other Decks in Programming

Transcript

  1. Properties of persistent data structures • Non-destructive updates • Explicit

    dependency tracking • Structural sharing • Substructures unaware of the larger whole
  2. Properties of persistent data structures • Non-destructive updates • Explicit

    dependency tracking • Structural sharing • Substructures unaware of the larger whole • Automatic space/memory management
  3. Nix

  4. Nix • Persistent, referentially transparent build tool/package management • Tracks

    graph of packages and their dependencies • Packages are built from source
  5. Nix • Persistent, referentially transparent build tool/package management • Tracks

    graph of packages and their dependencies • Packages are built from source • Builds specified with derivations in Nix, a pure, lazy, functional language
  6. Nix • Persistent, referentially transparent build tool/package management • Tracks

    graph of packages and their dependencies • Packages are built from source • Builds specified with derivations in Nix, a pure, lazy, functional language • Uses lot of tricks top revent relying on PATH, HOME, etc.
  7. Nix • Persistent, referentially transparent build tool/package management • Tracks

    graph of packages and their dependencies • Packages are built from source • Builds specified with derivations in Nix, a pure, lazy, functional language • Uses lot of tricks top revent relying on PATH, HOME, etc. • Packages installed in a directory based on hash of its derivation
  8. { stdenv, fetchFromGitHub, caddy, asciidoctor , file, lessc, sass, multimarkdown,

    linkchecker , perlPackages, python27 }: stdenv.mkDerivation rec { name = "styx-${version}"; version = "0.6.0"; . . . installPhase = '' mkdir $out install -D -m 777 styx.sh $out/bin/styx mkdir -p $out/share/styx cp -r scaffold $out/share/styx cp -r nix $out/share/styx mkdir -p $out/share/doc/styx asciidoctor doc/index.adoc -o $out/share/doc/styx/index.html https://github.com/NixOS/nixpkgs/blob/1e95402803adf28bd4d78403fa9e9dcccff12101/pkgs/applications/misc/styx/default.nix
  9. { stdenv, fetchFromGitHub, caddy, asciidoctor , file, lessc, sass, multimarkdown,

    linkchecker , perlPackages, python27 }: stdenv.mkDerivation rec { name = "styx-${version}"; version = "0.6.0"; . . . installPhase = '' mkdir $out install -D -m 777 styx.sh $out/bin/styx mkdir -p $out/share/styx cp -r scaffold $out/share/styx cp -r nix $out/share/styx mkdir -p $out/share/doc/styx asciidoctor doc/index.adoc -o $out/share/doc/styx/index.html https://github.com/NixOS/nixpkgs/blob/1e95402803adf28bd4d78403fa9e9dcccff12101/pkgs/applications/misc/styx/default.nix
  10. { stdenv, fetchFromGitHub, caddy, asciidoctor , file, lessc, sass, multimarkdown,

    linkchecker , perlPackages, python27 }: stdenv.mkDerivation rec { name = "styx-${version}"; version = "0.6.0"; . . . installPhase = '' mkdir $out install -D -m 777 styx.sh $out/bin/styx mkdir -p $out/share/styx cp -r scaffold $out/share/styx cp -r nix $out/share/styx mkdir -p $out/share/doc/styx asciidoctor doc/index.adoc -o $out/share/doc/styx/index.html https://github.com/NixOS/nixpkgs/blob/1e95402803adf28bd4d78403fa9e9dcccff12101/pkgs/applications/misc/styx/default.nix
  11. /nix/store |— 0c1p5z4kda11…-user-env | |— bin | |— svn |—

    3aw2pdyx2jfc…-user-env | |— bin | |— firefox | |— svn |— ihvrn5awaw7y…-user-env | |— bin | |— firefox | |— svn |— 5mq2jcn36ldl…-subversion-1.1.2 | |— bin | |— svn |— g32imf68vvbw…-firefox-1.0.1 | |— bin | |— firefox |— dpmvp969yhdq…-subversion-1.1.3 | |— bin | |— svn https://nixos.org/nix/manual/#sec-profiles /nix/var/nix/profiles |— default |— default-0-link |— default-1-link |— default-2-link
  12. /nix/store |— 0c1p5z4kda11…-user-env | |— bin | |— svn |—

    3aw2pdyx2jfc…-user-env | |— bin | |— firefox | |— svn |— ihvrn5awaw7y…-user-env | |— bin | |— firefox | |— svn |— 5mq2jcn36ldl…-subversion-1.1.2 | |— bin | |— svn |— g32imf68vvbw…-firefox-1.0.1 | |— bin | |— firefox |— dpmvp969yhdq…-subversion-1.1.3 | |— bin | |— svn https://nixos.org/nix/manual/#sec-profiles /nix/var/nix/profiles |— default |— default-0-link |— default-1-link |— default-2-link
  13. /nix/store |— 0c1p5z4kda11…-user-env | |— bin | |— svn |—

    3aw2pdyx2jfc…-user-env | |— bin | |— firefox | |— svn |— ihvrn5awaw7y…-user-env | |— bin | |— firefox | |— svn |— 5mq2jcn36ldl…-subversion-1.1.2 | |— bin | |— svn |— g32imf68vvbw…-firefox-1.0.1 | |— bin | |— firefox |— dpmvp969yhdq…-subversion-1.1.3 | |— bin | |— svn https://nixos.org/nix/manual/#sec-profiles /nix/var/nix/profiles |— default |— default-0-link |— default-1-link |— default-2-link
  14. /nix/store |— 0c1p5z4kda11…-user-env | |— bin | |— svn |—

    3aw2pdyx2jfc…-user-env | |— bin | |— firefox | |— svn |— ihvrn5awaw7y…-user-env | |— bin | |— firefox | |— svn |— 5mq2jcn36ldl…-subversion-1.1.2 | |— bin | |— svn |— g32imf68vvbw…-firefox-1.0.1 | |— bin | |— firefox |— dpmvp969yhdq…-subversion-1.1.3 | |— bin | |— svn https://nixos.org/nix/manual/#sec-profiles /nix/var/nix/profiles |— default |— default-0-link |— default-1-link |— default-2-link
  15. /nix/store |— 0c1p5z4kda11…-user-env | |— bin | |— svn |—

    3aw2pdyx2jfc…-user-env | |— bin | |— firefox | |— svn |— ihvrn5awaw7y…-user-env | |— bin | |— firefox | |— svn |— 5mq2jcn36ldl…-subversion-1.1.2 | |— bin | |— svn |— g32imf68vvbw…-firefox-1.0.1 | |— bin | |— firefox |— dpmvp969yhdq…-subversion-1.1.3 | |— bin | |— svn https://nixos.org/nix/manual/#sec-profiles /nix/var/nix/profiles |— default |— default-0-link |— default-1-link
  16. /nix/store |— 0c1p5z4kda11…-user-env | |— bin | |— svn |—

    3aw2pdyx2jfc…-user-env | |— bin | |— firefox | |— svn |— ihvrn5awaw7y…-user-env | |— bin | |— firefox | |— svn |— 5mq2jcn36ldl…-subversion-1.1.2 | |— bin | |— svn |— g32imf68vvbw…-firefox-1.0.1 | |— bin | |— firefox |— dpmvp969yhdq…-subversion-1.1.3 | |— bin | |— svn https://nixos.org/nix/manual/#sec-profiles /nix/var/nix/profiles |— default |— default-0-link |— default-1-link
  17. What did we gain? • Package installs will not clobber

    other packages • Trivial rollbacks and uninstalls
  18. What did we gain? • Package installs will not clobber

    other packages • Trivial rollbacks and uninstalls • Deterministic, reproducible builds (up to OS ABI)
  19. What did we gain? • Package installs will not clobber

    other packages • Trivial rollbacks and uninstalls • Deterministic, reproducible builds (up to OS ABI) • Safe:
  20. What did we gain? • Package installs will not clobber

    other packages • Trivial rollbacks and uninstalls • Deterministic, reproducible builds (up to OS ABI) • Safe: • Sharing packages across users
  21. What did we gain? • Package installs will not clobber

    other packages • Trivial rollbacks and uninstalls • Deterministic, reproducible builds (up to OS ABI) • Safe: • Sharing packages across users • Continuous integration
  22. What did we gain? • Package installs will not clobber

    other packages • Trivial rollbacks and uninstalls • Deterministic, reproducible builds (up to OS ABI) • Safe: • Sharing packages across users • Continuous integration • Caching packages
  23. Nelson • Continuous delivery system for immutable infrastructure • Immutable

    infrastructure taken to its logical conclusion • Tracks graph of service dependencies
  24. Nelson • Continuous delivery system for immutable infrastructure • Immutable

    infrastructure taken to its logical conclusion • Tracks graph of service dependencies • Semantic versioning (MAJOR.MINOR.PATCH)
  25. Nelson • Continuous delivery system for immutable infrastructure • Immutable

    infrastructure taken to its logical conclusion • Tracks graph of service dependencies • Semantic versioning (MAJOR.MINOR.PATCH) • Declare all dependencies
  26. Nelson • Continuous delivery system for immutable infrastructure • Immutable

    infrastructure taken to its logical conclusion • Tracks graph of service dependencies • Semantic versioning (MAJOR.MINOR.PATCH) • Declare all dependencies • Ingress/load balancers and jobs form the “root” of the graph
  27. units: - name: conductor description: description dependencies: - ref: [email protected]

    ports: - default->9000/http loadbalancers: - name: lb routes: - name: expose default expose: default->9000/http destination: conductor->default
  28. News Feed v0.1.0 Ingress ML v0.1.0 Friends v0.2.0 OSN v0.1.3

    Friends v0.3.0 Msngr v0.1.0 OSN v0.2.0
  29. What did we gain? • Deployments do not clobber other

    deployments • Reverting a deployment is just bleeding traffic back
  30. What did we gain? • Deployments do not clobber other

    deployments • Reverting a deployment is just bleeding traffic back • Fully automated application lifecycle
  31. What did we gain? • Deployments do not clobber other

    deployments • Reverting a deployment is just bleeding traffic back • Fully automated application lifecycle • Clear distinction between service owners vs. infra
  32. What did we gain? • Deployments do not clobber other

    deployments • Reverting a deployment is just bleeding traffic back • Fully automated application lifecycle • Clear distinction between service owners vs. infra • Engineering teams in charge of releasing, monitoring, etc.
  33. What did we gain? • Deployments do not clobber other

    deployments • Reverting a deployment is just bleeding traffic back • Fully automated application lifecycle • Clear distinction between service owners vs. infra • Engineering teams in charge of releasing, monitoring, etc. • No build team, ticket filing for deployments, etc.
  34. What did we gain? • Deployments do not clobber other

    deployments • Reverting a deployment is just bleeding traffic back • Fully automated application lifecycle • Clear distinction between service owners vs. infra • Engineering teams in charge of releasing, monitoring, etc. • No build team, ticket filing for deployments, etc. • Infra team focuses on infra!
  35. Summary • Immutability, persistence, referential transparency, etc. are not just

    for code • See also: event sourcing, Datomic, categorical databases
  36. Summary • Immutability, persistence, referential transparency, etc. are not just

    for code • See also: event sourcing, Datomic, categorical databases • Cross-pollination is good, FP ⇘ Systems
  37. Summary • Immutability, persistence, referential transparency, etc. are not just

    for code • See also: event sourcing, Datomic, categorical databases • Cross-pollination is good, FP ⇘ Systems • PL and FP folks: learn about systems, machine learning, etc. and share your knowledge
  38. Summary • Immutability, persistence, referential transparency, etc. are not just

    for code • See also: event sourcing, Datomic, categorical databases • Cross-pollination is good, FP ⇘ Systems • PL and FP folks: learn about systems, machine learning, etc. and share your knowledge • Systems folks: learn about programming languages, take ideas, build systems from solid foundations
  39. Further Reading • Nix • Website: https://nixos.org/ • Nix Pills:

    https://nixos.org/nixos/nix-pills/ • Dr. Eelco Dolstra’s PhD thesis: https://nixos.org/~eelco/ pubs/phd-thesis.pdf • Nelson • Website: https://getnelson.github.io/ • SF Infra as Code talk: https://youtu.be/lTIvKZHedJQ • Scale by the Bay talk: https://youtu.be/3EHtAA4oE0k
  40. EOF