The Issue With Auto Increment When Distributed
1:17

The Issue With Auto Increment When Distributed

Greg Hogg 22.05.2026 22 996 просмотров 705 лайков

Machine-readable: Markdown · JSON API · Site index

Поделиться Telegram VK Бот
Транскрипт Скачать .md
Анализ с AI
Описание видео
Auto-increment IDs cause major challenges when scaling a system across multiple distributed databases. In a single database auto-incrementing a number by one for each new record is simple and consistent. When you distribute the data across multiple servers they can no longer easily coordinate the next number. One solution is to configure each server with a unique starting offset and a fixed increment step. For example with three servers the first starts at one the second at two and the third at three. They all increment by three so the first server generates one four and seven while the second generates two five and eight. This approach works initially but becomes highly complex when you need to add or remove servers. Adding a fourth server requires recalculating the offset and increment step for every single machine in the cluster. Changing these configurations on live databases without causing ID collisions or downtime is incredibly difficult. To avoid this complexity some architectures use a centralized ticket server to hand out IDs. The ticket server acts as a single source of truth that increments a single counter for the entire system. However this centralized ticket server reintroduces a single point of failure into the architecture. It also creates a massive performance bottleneck which completely defeats the purpose of having a distributed system. This fundamental trade-off is exactly why companies like Twitter designed custom solutions like Snowflake IDs.

Оглавление (1 сегментов)

Segment 1 (00:00 - 01:00)

If you don't know this, you suck at system design. The most common type of ID is UUID, which for the most part is 128 random bits. The other common type is auto increment, where you start at one and you simply just plus one for each new row. When things get distributed, let me show you how auto increment completely falls apart. We have three servers, call them A, B, and C, and they all need to independently create unique IDs. If they're auto increment, then they all start at one, and immediately that's not unique, so that doesn't work. What you could do is start them all on an offset, say one, two, and three, and we keep counting by threes. So, this next one would be four, this would be five and six. Now, this works decently well for a fixed number of servers, say three. But if we had to add a new server, well, now everything has to go up by four, and we don't really know where to start this. So, it kind of falls apart at that stage. Now, to fix this auto increment idea, add a counter, an isolated server, and its job is to deliver tickets. Server A might ask, "Hey, what is the next number? " The counter would go up by one, the next number would be one. B would do the same, it's going to get two, and you could carry this on. But this kind of ruins the whole point, cuz now it's centralized. I teach this stuff every day and growing really fast, so follow along to learn more.

Другие видео автора — Greg Hogg

Ctrl+V

Экстракт Знаний в Telegram

Экстракты и дистилляты из лучших YouTube-каналов — сразу после публикации.

Подписаться

Дайджест Экстрактов

Лучшие методички за неделю — каждый понедельник