Skip to main content
Abhishek Tripathi
Curiosity brings awareness.
View all authors

Streaming HTTP to Disk

· 4 min read
Abhishek Tripathi
Curiosity brings awareness.

HTTP responses can be quite large and memory consumption can be a concern. In some cases, it is important to be able to handle large responses without loading the entire response into memory.

One such scenario is when you want to download a large file from a server. If you were to load the entire file into memory, it would require a large amount of memory and would be inefficient. Instead, you can use a streaming approach to download the file directly to disk.

This example will show you how to do just that using the reqwest and tokio crates (Rust). Here is the rough flow.

Understanding DDIA - Chapter 01,02

· One min read
Abhishek Tripathi
Curiosity brings awareness.

Question

Explain the key differences between relational databases and document databases. When would you choose one over the other?

Click to Flip

Solution

Here are the key differences between relational and document databases:

  1. Schema:
  • Relational: Rigid, predefined schema
  • Document: Flexible, schema-less design
  1. Data Model:
  • Relational: Data normalized across tables
  • Document: Denormalized, nested documents
  1. Scalability:
  • Relational: Vertical scaling primarily
  • Document: Easier horizontal scaling

Choose Relational when:

  • Data consistency is crucial
  • Complex queries and joins are needed
  • ACID compliance is required

Choose Document when:

  • Schema flexibility is needed
  • Rapid prototyping
  • Handling large amounts of unstructured data
  • Horizontal scaling is a priority
Click to Flip

Deep Flattening in Rust - Using Recursive Types

· 3 min read
Abhishek Tripathi
Curiosity brings awareness.

Deep Flattening in Rust: A Recursive Adventure

Flattening nested data structures is a common problem in programming. However, flattening structures with an arbitrary depth—like nested Vecs within Vecs—can be tricky. Rust, with its strong type system and trait-based polymorphism, allows us to implement elegant solutions to such problems. In this post, we'll explore a recursive approach to deep flattening in Rust using traits, type inference, and iterators.

The Goal

Given a deeply nested structure, such as:

let nested_vec = vec![
vec![vec![1, 2, 3], vec![4, 5]],
vec![vec![6], vec![7, 8, 9]],
];

Our goal is to flatten it into:

let flattened = vec![1, 2, 3, 4, 5, 6, 7, 8, 9];

1brc - same tricks across languages

· 3 min read
Abhishek Tripathi
Curiosity brings awareness.

The 1 Billion Row Challenge (1BRC) is a programming challenge focused on processing a large dataset of temperature measurements. If you're unfamiliar with it, you can learn more from these resources: 1 and 2.

This is a cheatsheet of optimisations done for 1brc challenges. It tries to summarise and put the optimisations in perspective.