EIDs

IDs in Crunchy Bridge are modeled after an in-house format called an "EID" ("encoded" ID), a 128-bit identifier encoded as a lowercase 26-character string using standard Base32-encoding as defined by RFC 4648. They're used instead of UUIDs because they're shorter, they fit nicely when included in a URL or DNS address, and are more easily selected and copied. For example, try double-clicking on rvf73a77ozfsvcttryebfrnlem to fully select it.

They're safe to store to local systems as strings, or alternatively for better space-effiency, can be parsed back to a 128 bits, and stored as a byte array or UUID instead.

The IDs of some resources are totally random (e.g. clusters), generated using the same algorithm as V4 UUIDs. Most new resources use the same time-based generation scheme as ULIDs instead (e.g. events). IDs have a significant random component (80 bits) and continue to be fully unique (with 1.21e+24 possible IDs for millisecond), but for user convenience, order according to when they were created.

Sample parsing and unparsing implementation

Below is sample code written in Go that shows how to parse and unparse an EID to an from a string which uses only the standard library. Implementation will vary from language to language, but most Base32 encoding libraries should be able to do the same.

package eid

import (
	"encoding/base32"
    "fmt"
	"strings"
)

var base32Packed = base32.StdEncoding.WithPadding(base32.NoPadding)

// EID represents an EID or "encoded" ID. It's convertible to and from a byte
// array or UUID.
type EID [16]byte

// Parse parses an EID from a string which should look something like
// "6ibnzig5avgutdgdzei2jwvvt4".
func Parse(s string) (EID, error) {
	if len(s) != 26 {
		return EID{}, fmt.Errorf("EID string should be exactly 26 characters long")
	}

	decoded, err := base32Packed.DecodeString(strings.ToUpper(s))
	if err != nil {
		return EID{}, fmt.Errorf("failed to decode EID: %w", err)
	}

	dst := [16]byte{}
	copy(dst[:], decoded)
	return EID(dst), nil
}

// String formats the EID as a string, with a result looking something like
// "6ibnzig5avgutdgdzei2jwvvt4".
func (id EID) String() string {
	return strings.ToLower(base32Packed.EncodeToString(id[:]))
}