Live data from Hacker News

Reddit's photo albums broke due to Integer overflow of Signed Int32

old.reddit.com

131–140 of 142 posts

Re: Reddit's photo albums broke due to Integer overflow of Signed Int32

#131

Earlier quoted context omitted.

This is really a false dichotomy you don't have to use guid/uuid. I'm saying even if you use sortable auto increment numbers, stop storing them like numbers.

Note that reddit is currently generating base36 ids starting with z. You want everything to treat that as text? Sure. That text has been 6 characters long for ages, and it's about to hit 7. I personally expect to see more things break when that happens. The problem of overflow isn't special to numbers.

You're certainly right that overflow isn't special to numbers, but my disdain for ids being treated as numbers mostly revolves around how common incidents like this are and how often a safe decision results in tempting developers to make unsafe decisions for api consistency.

Suppose you store your ids as a 64 bit number in the database, that's plenty of room, we shouldn't need to put an alarm for when we're reaching the end (although operationally you might want to still) - it's 9,223,372,036,854,775,807 when signed and 18,446,744,073,709,551,615 unsigned. That's a fine, sensible decision to make at the database level. Now suppose you have an API that interacts with these ids in the database and exposes them down to users in JSON. Javascript (and JSON by extension) numbers aren't integers they're double precision floating point numbers -- quick pop quiz, without looking, what's the maximum representable integer before you lose integer precision? Do all of your APIs work with auto increment numbers (which should still be safe) or are some of them vendor supplied, like UPCs or ISBNs? Will your developers remember this when they make a new API or will they look at an old api and think "it's a number there, I should match it"? Do some vendors front pad their numbers with 1s (this happened to us)? There are a lot of variables here and one big juicy thing developers want and know other developers want - consistency of rules. So I'm offering an easy, consistent rule:

Store it however your database lets you store it compactly, know your limits, set alarms, stop apologizing for database lack of features, but MOST IMPORTANTLY: insist to your developers that its type in code is a variable length utf-8 string, regardless of it's contents. Overflows happen, you need to accommodate them at business logic levels all the time, but stop letting developers trust numbers as being self-bound. They're not numbers in the URL, they're utf-8 letters in a string. They're not numbers in JSON, they're utf-8 letters in a string. Give them an a function that verifies the format of a string and stores it however you want in the database, but stop treating IDs like numbers even if they're numeric.

That's my opinion. Not that ints are a bad db row type.

Re: Reddit's photo albums broke due to Integer overflow of Signed Int32

#132
post #129
post #126

Earlier quoted context omitted.

Musk claimed a record of 20,000 of tweets per second recently [1]. How does that square with what you’re saying? 300 times 450 is closer to 150,000. Am I missing something? [1] https://twitter.com/elonmusk/status/1595505413113323520?s=20...

That tweet does not claim 20,000 is a record. The event also did not reach 20,000, it "almost" hit it.

You’re right. I misinterpreted ‘record usage’. I found a 2013 blog post [1] claiming a 143 thousand tweets per second peak.

[1] https://blog.twitter.com/engineering/en_us/a/2013/new-tweets...

Re: Reddit's photo albums broke due to Integer overflow of Signed Int32

#133

Earlier quoted context omitted.

Note that reddit is currently generating base36 ids starting with z. You want everything to treat that as text? Sure. That text has been 6 characters long for ages, and it's about to hit 7. I personally expect to see more things break when that happens. The problem of overflow isn't special to numbers.

You're certainly right that overflow isn't special to numbers, but my disdain for ids being treated as numbers mostly revolves around how common incidents like this are and how often a safe decision results in tempting developers to make unsafe decisions for api consistency. Suppose you store your ids as a 64 bit number in the database, that's plenty of room, we shouldn't need to put an alarm for when we're reaching…

> stop letting developers trust numbers as being self-bound

Sorry, I thought I was following you, but I don't understand the last half of this quote. What does "trust as self-bound" mean?

Re: Reddit's photo albums broke due to Integer overflow of Signed Int32

#134
post #9

Earlier quoted context omitted.

Strange thing is that photo albums re relatively new. Imgur was the go-to host for Reddit, and then they made their own uploader a looong time later. The "albums" functionality only came out in July of 2020, according to a Google search. Seems this was less likely a "someone else will deal with it" problem, and more of a development / QA testing problem.

For some reason most stuff still defaults to i32 and a lot of people use them for new code. At this point I'd not be against linters warning against using 32 bit ints unless you have a good reason.

What I don't get is why you'd want a signed int for an id.

Re: Reddit's photo albums broke due to Integer overflow of Signed Int32

#135

Earlier quoted context omitted.

> 52 bits because of javascript But IEEE 754 doubles have a significand that supports a 53-bit range. What am I missing?

negative numbers not used?

That doesn't make any sense.

Re: Reddit's photo albums broke due to Integer overflow of Signed Int32

#136

Earlier quoted context omitted.

I am pretty sure that snowflake didn't use a mod of a signed int32. It used a service discovery pool as part of finagle (and prior to that dns iirc). The server used a very simple method internally to convert time into a integer (that was 52 bits because of javascript). In fact it was completely open source: https://blog.twitter.com/engineering/en_us/a/2010/announcing... The integer generation was pretty simple, ther…

A simpler scheme I've used for adtech (billions of requests per day) is to simply reserve a chunk of numbers for each server from a central source. Easy to implement, very fast since each node can just increment in process, and using a 64-bit integer is effectively infinite.

That's how Active Directory Domain Controllers handle the distributed creation of SIDs too.

Re: Reddit's photo albums broke due to Integer overflow of Signed Int32

#137

Earlier quoted context omitted.

I am pretty sure that snowflake didn't use a mod of a signed int32. It used a service discovery pool as part of finagle (and prior to that dns iirc). The server used a very simple method internally to convert time into a integer (that was 52 bits because of javascript). In fact it was completely open source: https://blog.twitter.com/engineering/en_us/a/2010/announcing... The integer generation was pretty simple, ther…

> 52 bits because of javascript But IEEE 754 doubles have a significand that supports a 53-bit range. What am I missing?

You're not missing anything, people just forget the implied bit sometimes.

Re: Reddit's photo albums broke due to Integer overflow of Signed Int32

#138

Earlier quoted context omitted.

The bug never existed at all in Civ 1. It was an urban legend all along. Similar behavior was intentional in Civ 5 as a joke, which convinced everyone that it really did happen in Civ 1 when it never did.

Mandela effect

People being lied to is not the Mandela effect. The Mandela effect is about things you personally remember.

A Mandela effect here would be if the explanations themselves that talked about overflow never existed.

Re: Reddit's photo albums broke due to Integer overflow of Signed Int32

#139

Earlier quoted context omitted.

I always found the funniest occurrence of this was in the Civ game though it seems it originally being a bug is disputed. https://en.wikipedia.org/wiki/Nuclear_Gandhi

The bug never existed at all in Civ 1. It was an urban legend all along. Similar behavior was intentional in Civ 5 as a joke, which convinced everyone that it really did happen in Civ 1 when it never did.

Huh.

https://en.wikipedia.org/wiki/Nuclear_Gandhi

Re: Reddit's photo albums broke due to Integer overflow of Signed Int32

#140

Earlier quoted context omitted.

The comment starts with that assumption for the sake of a concise example. do you expect them to write the whole sequence out using a 32bit counter? :-D

When you divide 2^32 across 3 machines, you get 1431655766, 1431655765, 1431655765. They're nearly identical, just an itsy bitsy bit different. This isn't going to cause one machine to have noticeably less load than the others.

That's not what's being discussed here though.
Post reply on HN