Avoid overloading your systems: Request coalescing

The problem You are developing an application backed by a database, something happens and then several of your users try to access the same content. Several requests are sent to your backend at almost the same time and your backend hits the database once for each request to fetch the same data. Fetching the data only once If N requests asking for the same data arrive at the backend at around the same time, the backend could hit the database to fetch the data when the first request arrives and force the other requests to await until the data is fetched. When a response to the request sent to the database arrives at the backend with the data, the data can be shared with the requests that are waiting for it. ...

March 19, 2023 · 2 min · poorlydefinedbehaviour

Do Go programs with common data races compile in Rust?

Uber has adopted Go as its primary programming language for developing microservices and has a post on its blog called Data Race Patterns in Go where they talk about data races found in their Go codebase. I was reading it and thought to myself that many of the problems presented in the post would not even compile in Rust. Can Rust help us avoid writing code with common data races? Examples written in Rust are not meant do be idiomatic Rust and do not wait for outputs generated by tasks for simplicity because the examples written in Go do not wait as well. ...

May 23, 2022 · 11 min · poorlydefinedbehaviour

Logs

What is a log A log is just a immutable sequence of records wih strong ordering semantics that can be used to provide durability, replication and to model consensus. It is usually a 0 indexed file that new entries are appended to because expensive disk seeks can usually be avoided when appending to a file1. Not to be confused with the type of logs most people are used to: application logs that are meant to be read by humans although application logs are a degenerative case of the log we are talking about2. ...

April 30, 2022 · 2 min · poorlydefinedbehaviour

Contributing to Rust and tokio

Contributing for the first time I have been trying to force myself to do harder things lately in order to practice and learn new things. Since i’m doing Rust full time now, i thought it would be a good a idea to contribute to the ecosystem, so i went and enabled notifications for a bunch of Rust related projects and for the Rust project itself. I thought i would be able to keep up with the notifications. I was wrong. (obviously) ...

April 17, 2022 · 13 min · poorlydefinedbehaviour

Why Rc<T> is not Send

Why Rc cannot be sent between threads We get a compile error if we try to send Rc<T> to another thread: use std::rc::Rc; fn main() { let rc = Rc::new(1); std::thread::spawn(|| { println!("{}", *rc); }) .join(); } error[E0277]: `Rc<i32>` cannot be shared between threads safely --> src/main.rs:5:3 | 5 | std::thread::spawn(|| { | ^^^^^^^^^^^^^^^^^^ `Rc<i32>` cannot be shared between threads safely | = help: the trait `Sync` is not implemented for `Rc<i32>` = note: required because of the requirements on the impl of `Send` for `&Rc<i32>` = note: required because it appears within the type `[closure@src/main.rs:5:22: 7:4]` note: required by a bound in `spawn` --> /home/bruno/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/std/src/thread/mod.rs:625:8 | 625 | F: Send + 'static, | ^^^^ required by this bound in `spawn` For more information about this error, try `rustc --explain E0277`. The compile error is triggered because the closure passed to std::thread::spawn must be Send. Types that implement Send are types that can be transferred across thread boundaries. ...

March 27, 2022 · 4 min · poorlydefinedbehaviour