A barcode checksum can detect a typo without proving that the code belongs to your business. Product identity needs three layers: an immutable internal ID, an allocation policy for merchant SKUs and an externally assigned identifier where applicable.
Exhaustively changing every digit of one GTIN-shaped string
We calculated a valid check digit for the synthetic twelve-digit body 123456789012, then substituted each of the 13 positions with each of its nine alternative digits. The experiment evaluated 117 single-digit changes using the alternating 3/1 weight rule. None passed the checksum. The synthetic test value 1234567890128 is not an assigned product GTIN and must not be used as one.
function checkDigit(body) {
const total = [...body].reverse().reduce(
(sum, digit, i) => sum + Number(digit) * (i % 2 ? 1 : 3), 0
);
return (10 - total % 10) % 10;
}
This outcome follows from modular arithmetic: both 1 and 3 are coprime to 10, so a nonzero one-digit change cannot preserve the weighted sum modulo ten. It does not prove detection of every multi-digit error. For example, adjacent digit transpositions whose digits differ by five can leave the checksum unchanged. GS1's check-digit calculator is an independent reference.
Do not treat a checksum as a catalog identity
GTIN syntax validates a number's structure, not whether it is allocated to a specific trade item. An SKU is a merchant-local reference; a barcode is an encoding of a value. Keep the internal UUID, SKU, external code and packaging level separate. Store these as strings so leading zeros survive import. Our coercion experiment shows the danger of treating identifiers as numbers.
Why a sequential SKU still needs a uniqueness constraint
-- Scope reflects a shared tenant catalog.
CREATE UNIQUE INDEX product_sku_unique
ON products (tenant_id, sku);
Two workers can generate the same readable SKU before either inserts. The atomic reserve contract in Inventory IDs retries a collision; it does not coordinate external stock movements by itself. A retired SKU should remain reserved or carry an explicit alias history rather than being silently assigned to another product.
A scanner is an input device, not a transaction
Resolve a scan through the tenant's identifier table, require a defined packaging unit and store the immutable variant ID in the sale. A pack barcode may represent several units. Printing a new label must not create a duplicate product or modify stock. Unknown codes go to a controlled workflow. Read Merchant feed reconciliation for the external identity mapping.
Use test coverage that matches operational failures
In addition to digit mutation tests, test collisions, unknown codes, duplicate labels, packaging conversions and product retirement. Measure the first-pass scan rate using actual scan attempts; distinguish hardware failures from missing catalog records. POS and atomic reservation design depend on stable identities. The checksum experiment establishes one narrow mathematical property, not a measured scanning success rate.
Method and reproducibility: Controlled synthetic model. See Code Deb's recorded experiment results and reproduction script in the repository. Figures are reproducible from declared inputs, not undisclosed client outcomes. The cited external material is independent of Code Deb's experiment.