惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

MongoDB | Blog
MongoDB | Blog
宝玉的分享
宝玉的分享
博客园 - 三生石上(FineUI控件)
小众软件
小众软件
罗磊的独立博客
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
S
SegmentFault 最新的问题
Last Week in AI
Last Week in AI
人人都是产品经理
人人都是产品经理
博客园 - 聂微东
博客园 - 司徒正美
博客园 - 叶小钗
T
Tailwind CSS Blog
博客园 - Franky
V
V2EX
有赞技术团队
有赞技术团队
美团技术团队
雷峰网
雷峰网
爱范儿
爱范儿
Jina AI
Jina AI
D
DataBreaches.Net
H
Help Net Security
酷 壳 – CoolShell
酷 壳 – CoolShell

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Designing a Transaction ID for a Payment System: What I L...
A. S. M. Tar · 2026-05-06 · via DEV Community

Recently, I worked through the design of a 10-character customer-facing transaction ID. It looks trivial. It is not.

Here's the journey, and the design that survived.

THE CONSTRAINTS

  • Exactly 10 characters
  • Alphanumeric
  • Globally unique, forever
  • Customer-facing — read aloud, typed on phones, screenshotted, dictated to support agents

That last point is what makes this hard. An internal ID can be ugly. A customer-facing ID has to survive the real world.

THE OPTIONS I CONSIDERED

  1. Sequential counter (1, 2, 3...)
    • Wastes most of UUID's randomness
    • Higher collision probability than necessary
  2. UUID truncated to 10 chars
    • Encoding 64 bits into 10 chars requires lossy truncation
    • Time-ordered IDs leak business metrics
  3. Snowflake-style (timestamp + machine ID + sequence)
    • Leaks transaction volume to anyone watching
    • Predictable + fraud risk
  4. Timestamp + random hybrid
    • In a large system (~10K TPS), multiple transactions share the same millisecond
    • Time portion eats your character budget
    • A 4-character Base62 timestamp overflows in ~5 months
    • Still leaks volume
  5. Pure CSPRNG random + DB unique constraint ✅

A Cryptographically Secure Pseudo-Random Number Generator (CSPRNG) is an algorithm designed to produce sequences of numbers that are practically indistinguishable from true randomness and, crucially, are unpredictable.

THE FINAL DESIGN

  • 9 random characters from Crockford Base32
  • 1 Damm checksum character
  • Database UNIQUE constraint as the source of truth
  • Bounded retry on the rare collision

Why Crockford Base32 (not Base62)?

The alphabet is "0123456789ABCDEFGHJKMNPQRSTVWXYZ" — 32 characters, all uppercase, with I, L, O, U deliberately removed.

Why? Because every customer-facing ID eventually gets:
✓ Read over a phone call
✓ Typed on a small keyboard
✓ Screenshotted and re-typed by someone else
✓ Spoken in Bangla, English, or both

Mixed-case Base62 might give you more entropy per character, but it creates real failure modes:
"Capital K or small k?"
"Was that O or zero?"
"That's a 1, an l, or an I?"

Single-case Crockford Base32 eliminates these conversations entirely.

WHY DAMM CHECKSUM?

Most homemade checksums use weighted sums like sum(i * char_value) mod N. These catch single-character typos but miss adjacent transpositions ("KH" mistyped as "HK") — which is the SECOND most common human error.

Damm checksum, when applied over a 32-symbol quasigroup, catches:
✓ 100% of single-character substitutions
✓ 100% of adjacent transpositions

For a payment system where customers dictate IDs over the phone, this matters a lot. A miss here means a customer's typo gets accepted as valid and looks up the wrong transaction.

WHY NOT JUST USE EPOCH AS A SEED?

A common temptation: "Let me seed Random() with currentTimeMillis() for extra randomness."

This is a security anti-pattern.

  • java.util.Random has only 48 bits of state — recoverable from 2 outputs
  • Epoch time has only ~10 bits of entropy if the attacker knows roughly when
  • XOR-ing low-entropy sources doesn't create high entropy

SecureRandom already pulls from the OS entropy pool — clock readings, hardware interrupts, RDRAND, the works. Mixed by experts who audit it for a living.

The rule: trust your CSPRNG. Don't try to "improve" it.

THE NUMBERS

Random portion keyspace: 32^9 ≈ 35 trillion

Even at 1 billion transactions issued, the per-insert collision probability is:
10^9 / (3.5 × 10^13) ≈ 0.00003

That's about 1 retry per 35,000 inserts — completely operational.
The DB UNIQUE constraint catches it; the app retries; the customer never knows.

KEY LESSONS

  1. Customer-facing IDs are a UX problem first, an engineering problem second.
  2. Time in the ID is a leak, not a feature. Keep timestamps in a separate column.
  3. A large random keyspace + a DB unique constraint is simpler and safer than any "guarantee uniqueness" algorithm.
  4. The checksum matters more than people think. Use Damm or Verhoeff, not a homemade weighted sum.
  5. SecureRandom is the floor, not the ceiling. Anything less is malpractice for payments.
  6. Keep internal sequence IDs (BIGSERIAL) for ordering and audit. Never expose them to customers.

If you're designing payment infrastructure, financial IDs, or any high-stakes user-facing identifier — happy to discuss in the comments.

What does your team use for transaction ID generation? Any war stories?