LUC #82: Database Indexing Clearly Explained

Plus, how OAuth 2.0 works, Kubernetes in a nutshell, and the most popular database cahcing strategies explained

This week’s issue brings you:

READ TIME: 5 MINUTES

Thanks to our partners who keep this newsletter free to the reader.

Postman’s new Spec Hub is a game-changer. It brings API design, testing, and documentation into one seamless experience—so you can stop syncing across platforms and start shipping faster.

Here’s what stands out:

  • Design with OpenAPI & AsyncAPI support

  • Auto-generate collections from your specs

  • Keep tests & docs updated automatically

  • Validate requests/responses with new typed collections

Whether you work spec-first or collection-first, Postman’s unified approach fits your flow.

Understanding the Various Approaches to Effective Database Indexing

Most databases require some form of indexing to keep up with performance benchmarks. Searching through a database is much simpler when the data is correctly indexed, which improves the system's overall performance.

A database index is a lot like the index on the back of a book.

It saves you time and energy by allowing you to easily find what you're looking for without having to flick through every page.

Database indexes work the same way.

An index is a key-value pair where the key is used to search for data instead of the corresponding indexed column(s), and the value is a pointer to the relevant row(s) in the table.

To get the most out of your database, you should use the right index type for the job.

One of the most commonly used indexing structures is the B-tree, where keys are sorted and organized in a hierarchical tree structure.

When searching data, the tree is traversed down to the leaf node that contains the appropriate key and pointer to the relevant rows in the table.

B-tree is most commonly used because of its efficiency in storing and searching through ordered data. Their balanced structure means that all keys can be accessed in the same number of steps, making performance consistent.

Hash indexes are best used when you are searching for an exact value match.

The key component of a hash index is the hash function.

When searching for a specific value, the search value is passed through a hash function which returns a hash value. That hash value tells the database where the key and pointers are located in the hash table.

For indexing columns with a low set of unique values, bitmap indexing can be used.

With bitmap indexing, each bitmap represents a unique value. A bitmap indicates the presence or absence of a value in a dataset, using 1’s and 0’s. For existing values, the position of the 1 in the bitmap shows the location of the row in the table.

Bitmap indexes are very effective in handling complex queries where multiple columns are used.

When you are indexing a table, make sure to carefully select the columns to be indexed based on the most frequently used columns in WHERE clauses.

composite index may be used when multiple columns are often used in a WHERE clause together.

With a composite index, a combination of two or more columns are used to create a concatenated key. The keys are then stored based on the index strategy, such as the options mentioned above.

Indexing can be a double-edged sword. It significantly speeds up queries, but it also takes up storage space and adds overhead to operations. Balancing performance and optimal storage is crucial to get the most out of your database without introducing inefficiencies.

How OAuth 2.0 Works (Recap)

OAuth 2.0 is an authorization framework that enables applications to access a user’s data on another service without sharing the user’s password. It’s essentially a digital handshake between the appservice, and user, with everyone agreeing on what is shared.

The process generally follows 6 steps:

🔸 1) Request access
🔸 2) Redirect to service
🔸 3) Permission request
🔸 4) Authorization code
🔸 5) Exchange code for token
🔸 6) Use the token

There are typically 4 components involved in the process:

🔹 Client (app wanting access)
🔹 Resource owner (user)
🔹 Authorization server
🔹 Resource server

Kubernetes In a Nutshell (Recap)

Kubernetes (K8s) is an open-source platform that automates the deployment, scaling, and management of containerized applications.

How it works: A Kubernetes cluster consists of worker nodes that host and run application Pods, while the control plane orchestrates scheduling, scaling, and overall cluster management.

Key components:

  • Pods: The smallest deployable unit that encapsulates one or more containers.

  • Services: Provide stable network endpoints for Pod communication.

  • Control Plane: Oversees cluster operations to ensure desired state and health.

  • etcd: A distributed key-value store maintaining cluster configuration and state.

Core features: Auto-scaling, self-healing, load balancing, multi-cloud support, and declarative configurations.

Use cases: Ideal for microservices, CI/CD, cloud-native apps, stateful workloads, batch processing, and more.

Kubernetes offers scalability and automation but has a steep learning curve.

Five of the most common methods:

Cache-aside strategy — applications control caching by checking the cache before the database. Ideal for dynamic data but requires manual management, increasing complexity.

Write-through strategy — writes simultaneously to the cache and database, ensuring consistency. Suitable for high reliability but increases write latency.

Write-behind strategy — caches data first and updates the database asynchronously. Boosts responsiveness but risks data loss if the cache expires before syncing.

Read-through strategy — automatically caches data on a miss, simplifying code. Initial cache misses can delay retrieval.

Write-around strategy — writes directly to the database, refreshing the cache on read requests. Prevents cache saturation, best for write-intensive applications without immediate read access needs.

That wraps up this week’s issue of Level Up Coding’s newsletter!

Join us again next week where we’ll explore and visually distill more important engineering concepts.