Posts

Showing posts from October, 2025

Prepending to a Vec in Rust: What Are Your Options?

Rust’s Vec is a powerful and flexible collection type. It’s fast at pushing and popping at the end , but sometimes you need to add an element to the front . That’s where things get tricky: Vec is backed by a contiguous array, so prepending requires shifting or reallocating elements. There’s no O(1) way to do this. In this post, we’ll walk through several ways to prepend to a Vec , compare their mechanics, and discuss when each is appropriate. The Problem You have a vector: let mut digits = vec![2, 3, 4]; You want to add 1 to the head , so that the result is [1, 2, 3, 4] . Option 1: Using insert(0, value) The simplest and most idiomatic solution: digits.insert(0, 1); Shifts all elements one place to the right. Uses ptr::copy under the hood (a single memmove ). Complexity: O(n) . This is usually the best choice unless you need to squeeze out every last cycle. Option 2: Build a New Vec With Capacity If you’re fine creating a new vector: let mut result = Vec::wi...

22 Advanced DynamoDB Gotchas You Don’t Want to Learn the Hard Way

Amazon DynamoDB promises near-infinite scalability, serverless operations, and low-latency performance. It’s a solid foundation for many cloud-native applications — from IoT to real-time analytics. But beneath the simplicity lies a jungle of design decisions, silent failures, and performance pitfalls. Whether you’re new to DynamoDB or an experienced AWS developer, these 22 advanced gotchas will help you avoid painful lessons in production. 1. Hot Partitions (Skewed Access) DynamoDB automatically partitions your data, but if too many requests hit the same partition key, it results in throttling. A common mistake is using low-cardinality partition keys like region = "US" or active user_id s, creating hot spots under load. Fix : Use high-cardinality partition keys or introduce artificial sharding (e.g., appending a random number to the key). 2. Exceeding the 400KB Item Size Limit Every DynamoDB item (including all attributes) must be under 400KB. This limit includes o...