Featured Blog Texture

Blog

Engineering

RAFT 2

Engineering

Raft is so fetch: The Raft Consensus Algorithm explained through "Mean Girls"

Raft is a consensus algorithm used in distributed systems to ensure that data is replicated safely and consistently. That sentence alone can be confusing. Hopefully the analogy in this post can help people understand how it works. In honor of national Mean Girls day (“on October 3rd he asked me what day it was”), I present the Raft Consensus Algorithm as explained through the movie Mean Girls. (For a great, more technical overview of Raft, we recommend The Secret Lives of Data).

Mikael Austin

Mar 13, 2024

GC Mei-Li-Nieuwland-1

Engineering

How to optimize garbage collection in Go

After publishing \\[a post about why we chose Go for CockroachDB](https://www.cockroachlabs.com/blog/why-go-was-the-right-choice-for-cockroachdb/), we received questions about how we deal with some of Go’s known issues — especially those related to performance, garbage collection, and deadlocks.

jessica headshot

Jessica Edwards

Sept 26, 2023

retail-blog-header-12

Community

Engineering

Product

How to solve the `abandoned cart problem` using row-level TTL

We’ve all done it. Imagine you’re browsing around the AllSaints online shop, dreaming about refreshing your fall wardrobe. You find a couple items and add them to your cart. You continue browsing but then, for some reason, you don’t check out. Instead, you close the browser tab and move on. In the e-commerce world, this is what’s known as shopping cart abandonment.

aydrian

Aydrian Howard

July 26, 2023

Cockroach-Labs-Blog-TARDIS-1

Engineering

Time, TIMETZ, Timestamp, and TimestampTZ in PostgreSQL

At Cockroach Labs, we’ve spent a lot of time getting our SQL semantics to match PostgreSQL as much as possible - all so that you can use the awesome PostgreSQL language with a powerful, distributed backend like! Getting this right involves getting the Time, TimeTZ, Timestamp and TimestampTZ types right - which has proven quite the quest! Numerous bugs have been filed and fixed - and with it, our mastery of these types in PostgreSQL (and the Go time library) has increased! In this blog post, we’ll explore some intricacies we’ve found with these data types in PostgreSQL, and look at how we reproduce some of these features using Go and its ecosystem. We’ll share our recommendations for using these types along the way.

Oliver Tan

July 10, 2023

foreign-key-1

Engineering

3 common foreign key mistakes (and how to avoid them)

Foreign keys are an important element of any relational database. But when you’re setting up your database schema, it’s relatively easy to create problems for yourself if the foreign keys aren’t set up correctly. Here are three of the most common mistakes made with foreign keys, and a little advice on how to avoid them!

charlie

Charlie Custer

June 28, 2023

fast-cockroach

Engineering

Performance Benefits of NOT NULL Constraints on Foreign Key Reference Columns

NOT NULL constraints are a ubiquitous tool for upholding data integrity. However, their performance benefits are less obvious. NOT NULL constraints provide a query optimizer with additional context that unlocks optimizations that significantly reduce query latency. In this post we’ll examine a few of these optimizations that transform query plans involving foreign key relationships.

1128750

Marcus Gartner

June 27, 2023

blog-header-fast-cockroach

Engineering

Increase query speed with Forward Indexes on JSON columns

During the Winter of 2023, I had the wonderful opportunity to work as a Software Engineering Intern on the SQL Queries team at Cockroach Labs. During the scope of this internship, I found myself working with indexes and specifically implementing forward indexes on columns storing JSONB, which resulted in speeding up query execution time by up to 98% in some cases! This blog post will go over the motivations for the implementation of these indexes, the main challenges that came up with the implementation, and some demonstrations of the staggering results.

Shivam Saraf

June 13, 2023

what-is-a-database-hotspot-blog-header

Engineering

What is a database hotspot, and how do you fix it?

In a distributed database, a hotspot is an overworked node – in other words, a part of the database that’s processing a greater share of the total workload than it is meant to handle.

charlie

Charlie Custer

June 7, 2023

foreign-key-2

Engineering

What is a foreign key? (with SQL examples)

A foreign key is a column or columns in a database that (e.g. table_1.column_a) that are linked to a column in a different table (table_2.column_b). The existence of a foreign key column establishes a foreign key constraint – a database rule that ensures that a value can be added or updated in column_a only if the same value already exists in column_b.

charlie

Charlie Custer

May 4, 2023

foreign-key-3

Engineering

Database schema: SQL schema examples and best practices

In the context of a database and how it’s organized, the term database schema describes the structure of the data and how the elements within the database relate to each other. This information is often presented visually with diagrams that illustrate how different tables and elements connect and to give you a logical view of the entire database. However, the schema itself exists in the database as the coded rules that define the data’s structure and relationships.

charlie

Charlie Custer

Apr 13, 2023