5 ms·
That start ids at a gigantic number idea is great, even though I've never encountered a bug caused by not doing it.
by bryanrasmussen 6y ago
That start ids at a gigantic number idea is great, even though I've never encountered a bug caused by not doing it.
- joss82 6y agoIndeed, that and sql syntax errors are solved by using an orm or sql code generator like sql alchemy core.
- boatmansloth 6y agoI literally came here to comment that the very first bug I had to chase down in a production system in my first job was caused by this! There was a 'fuzzy' search field available to users and when one input a client's ID number (formatted as NNNNNNN) it was showing results for a different client because NNNNNNN was also the format of the unique ID for records in the database.
- tpetry 6y agoA better tip would be to use something like time-ordered uuids: You can‘t misuse them for something different and the added bonus is that no one can iterate your db records by just incrementing the url.
- Cthulhu_ 6y agoMy main gripe with UUIDs at the moment is that they look ugly in urls :/
- pretzelhands 6y agoThey're not the prettiest sight, yes, but I think anyone who isn't in some way a geek particularly cares about what's actually in URLs. There's a reason why Apple got away with only showing the hostname of a URL: It doesn't matter to ordinary people. :)
- krab 6y agoYou can encode it to a shorter string if you use larger alphabet. Still, it's 16 bytes of information, so not as short as sequential IDs. See for example https://pypi.org/project/shortuuid/ https://pypi.org/project/shortuuid/ >>> shortuuid.uuid() 'vytxeTZskVKR7C7WgdSP3d'
- ivanbakel 6y agoThose shorter strings can come with their own caveats. Long-form UUIDs have the nice property of being URL-safe - but IIRC, path pieces in HTTP urls are not meant to be case-sensitive, and browsers have historically tried to "help" by re-casing URLs. For correct semantics, short UUIDs have to go in the request parameters instead.
- account42 6y ago> IRC, path pieces in HTTP urls are not meant to be case-sensitive, and browsers have historically tried to "help" by re-casing URLs. That would break with any webserver that is serving files from a case-sensitive filesystem. Which is most of them.
- Deadron 6y agoWindows....enough said.
- hansvm 6y agoMost of the url (including the path pieces) is supposed to be case sensitive unless otherwise specified for a given protocol (and treating e.g. %3A the same as %3a). This should be the most recent RFC on the topic: https://tools.ietf.org/html/rfc3986#section-6.2.2.1 https://tools.ietf.org/html/rfc3986#section-6.2.2.1
- ozim 6y agoYou should not use your database identifiers in urls anyway.
- codingdave 6y agoIf you are implying that having an un-guessable URL secures your data, you might want to reconsider that approach. Your data should be secured server-side based on the actual auth in your app.
- derwiki 6y agoNot the OP but I read it as “much harder to scrape” than making it Secure. Which has some value.
- fumblebee 6y agoI once debugged a case where the id had left sided zero padding so the whole id length was a fixed number of digits, for example `238974` might be represented as `00238974`. In a process that joined two tables the match counts were off. Somehow, on one side of the join the id was being converted to an integer and then back to a string, which stripped the zero padding. Meaning that `00238974` was failing to match `238974`. Sigh.
- genezeta 6y agoNot bugs but I've encountered a consequence which is worse than a bug. In a recent project I arrived at, I started seeing 612 in random places in the code. It was, naturally, the ID of a very specific user. Having an easy ID to remember, it is a temptation for sloppy programmers to just hardcode certain checks against a particular ID instead of following proper procedures. It was a bad project and a bad team, and after some 10 years or so, the code was now flooded with 612 and a couple of other IDs. Sure, you could avoid such a thing with code revisions and such, but then again it's better to simply not put the temptation in front of the programmers, isn't it?
- deleted 6y ago[deleted]
- acdha 6y agoI encountered a similar problem recently while migrating an old app. It modeled IDs as 64-bit BIGINT columns (a decision made in the 2000s) and populated them with MySQL’s UUID_SHORT function. This worked fine for over a decade until we migrated to a different MySQL system and started getting conflicts for IDs already existing or not being able to find a row which had just been inserted. They’d missed the part that UUID_SHORT() returns an unsigned integer and created the column as the default signed integer. MySQL uses an algorithm where the top n bits are based on the server ID, which worked on the old server which had id=1 and never returned a number where the first bit was 1. The new cluster fortunately always did so the problem was immediately identified, but it was confused by one of those bonus MySQL data-destruction features – the way it silently truncated data meant that it was silently truncating new IDs to the same value but the logged value wasn’t in the database at all.
- MaxBarraclough 6y agoI like that pattern too. I've tried using it in a rather ad-hoc way in C/C++ enums. I suppose the proper solution would be to have a header file, enum_starting_vals.h, to centralise them.