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.

7a04b88e1469561db6da3818348d4b8f?s=128

Alexey Novakov

March 24, 2020
Tweet

Transcript

  1. Blazing Fast Microservices in Rust and Docker ALEXEY NOVAKOV, ULTRA

    TENDENDCY, MARCH 2020
  2. 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
  3. Applications of Rust today

  4. Web development, WebAssembly Command line utilities Games Operating Systems Networking

    Microcontroller programming Microservices (Cloud) Not for Big Data yet
  5. 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 = "*"
  6. 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 + "]" } }
  7. 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 )
  8. Use Case - Generate Random Data - Insert Data into

    Postgres database based on Cron expression - Run as Docker container
  9. Crates •diesel •serde_derive •job_scheduler •rand •chrono

  10. 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
  11. Go to the Code https://github.com/novakov-alexey/data-gen

  12. 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