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

Blazing Fast Microservices in Rust and Docker

Blazing Fast Microservices in Rust and Docker

Short overview of Rust and example of data generator application built with diesel, chrono, job_scheduler crates.

Alexey Novakov

March 24, 2020
Tweet

More Decks by Alexey Novakov

Other Decks in Programming

Transcript

  1. Rust - System programming language focused on safety and performance

    - Syntactically like C++ - No explicit runtime - No Garbage Collector and no manual memory management like in C
  2. Web development, WebAssembly Command line utilities Games Operating Systems Networking

    Microcontroller programming Microservices (Cloud) Not for Big Data yet
  3. Build Tool and Crates ◦ Cargo.toml: [package] name = "data-gen"

    version = "0.1.0" [dependencies] rand = "0.7.3" chrono = "0.4" serde = "1.0" serde_derive = "1.0" job_scheduler = "*"
  4. What is great in Rust - Fast startup and small

    binary size - Generics and Traits - Explicit immutable vs. mutable aspect - Pattern Matching - Compiler Error Messages - Fast compilation if you come from JVM - No Null - No classes pub trait Formatter<T> { fn fmt(&self) -> String; } 
 impl Formatter<Self> for &str { fn fmt(&self) -> String { "[string: ".to_owned() + &self + "]" } }
  5. What is not so great in Rust - Dealing with

    "borrow checker" errors - No High-Order Types - Too verbose C++ like syntax, if you come from Scala or Haskell (semicolons, curly braces, lambdas )
  6. Use Case - Generate Random Data - Insert Data into

    Postgres database based on Cron expression - Run as Docker container
  7. Results • Docker image Size: 7.79MB • Startup: 0m0,061s docker

    logs 35f048a38722 [2020-03-24T11:03:13Z INFO data_gen] starting up [2020-03-24T11:03:13Z INFO data_gen] Data Generation Job scheduled with: 1/10 * * * * * [2020-03-24T11:03:21Z INFO data_gen] Generated records: 12 [2020-03-24T11:03:31Z INFO data_gen] Generated records: 7
  8. Thank you! Questions? Alexey Novakov email: - alexey.novakov at ultratendency.com

    - novakov.alex at gmail.com Blog: https://medium.com/se-notes-by-alexey-novakov https://novakov-alexey.github.io/ Code: https://github.com/novakov-alexey Twitter: @alexey_novakov