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. Blazing Fast
    Microservices in Rust
    and Docker
    ALEXEY NOVAKOV, ULTRA TENDENDCY, MARCH 2020

    View Slide

  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

    View Slide

  3. Applications
    of Rust today

    View Slide

  4. Web development, WebAssembly
    Command line utilities
    Games
    Operating Systems
    Networking
    Microcontroller programming
    Microservices (Cloud)
    Not for Big Data yet

    View Slide

  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 = "*"

    View Slide

  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 {
    fn fmt(&self) -> String;
    }

    impl Formatter for &str {
    fn fmt(&self) -> String {
    "[string: ".to_owned() + &self + "]"
    }
    }

    View Slide

  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 )

    View Slide

  8. Use Case - Generate Random Data
    - Insert Data into Postgres database based on Cron expression
    - Run as Docker container

    View Slide

  9. Crates
    •diesel
    •serde_derive
    •job_scheduler
    •rand
    •chrono

    View Slide

  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

    View Slide

  11. Go to the Code
    https://github.com/novakov-alexey/data-gen

    View Slide

  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

    View Slide