Show HN: Order Stamps – A String-Based Trick for Effortless List Ordering

github.com

2 points by justagoat 4 hours ago

Hey HN,

our small team recently stumbled onto a neat approach for handling ordered lists in DBs without all the reindexing headaches. We’ve been calling it Order Stamps, and we originally built it for our own distributed database project, GoatDB. The concept is simple—treat the “position” of each list item as an infinitely splittable string rather than an integer index.

Why bother? Ever inserted an item “in the middle” of a large list and had to reorder everything afterward? We wanted O(1) list operations so you only ever update a single row per insertion/deletion.

How to use it? Just add a string order column to your rows, then call the start() or end() functions to generates stamps that insert at either ends. There's also the between() function that generates a stamp between two others. Finally, just sort by this order column to get the correct list.

The order of these stamps remain consistent even if you filter a subset of the rows, and it's also collision resistant so stamps can be safely generated without coordination.

How does it work? Think of “AA” and “AB.” If you want something in the middle, pick “AAM” or “AAX” or keep making up new strings. There’s always room for more “in-between” values because strings can keep growing.

We’re curious if this approach might be useful to you. Our code is a small TypeScript utility—no heavy lifts—and it plays nicely with standard DB indexes so your range queries stay fast.

What do you think? We’d love the community’s take on the design choices or edge cases we might not have considered. We hope you’ll dig into the code and give us your thoughts! If you end up using Order Stamps (with or without GoatDB), let us know how it goes.

Github Repo: https://github.com/goatplatform/orderstamp-js

Looking forward to your feedback—thanks for reading!