Content
I recently needed QR codes for a client project and discovered a fundamental architecture decision: static vs dynamic. While they look the same to a user, the engineering behind them is vastly different.
The Architecture of Static QR Codes
Static QR codes are serverless. The data (URL, text, vCard) is directly encoded into the matrix pattern. Once generated, it's immutable.
How it works:
Input: "https://example.com"
Encoding: The string is converted to binary and Reed-Solomon error correction is added.
Rendering: Binary data is drawn as black/white modules.
javascript
// Simple Static Generation (Node.js)
import QRCode from 'qrcode';
const generateStaticQR = async (url) => {
return await QRCode.toDataURL(url);
};
Pros: Zero infrastructure, works offline, free. Cons: Cannot be changed, no analytics.
The Architecture of Dynamic QR Codes
Dynamic QR codes are essentially "short links" printed as graphics. They allow you to track scans and change the destination URL without reprinting the code.
System Components:
Generator Service: Creates a unique short ID (e.g., qrmaster.net/abc1234).
Database (PostgreSQL): Stores the mapping abc1234 -> https://target.com plus metadata (owner, created_at).
Redirect/Edge Server (Node.js/Redis): Handles the incoming request, logs the scan, and issues a 302 Found redirect.
javascript
// Dynamic Redirect Logic (Express + Redis)
app.get('/:shortId', async (req, res) => {
const { shortId } = req.params;
// 1. Check Cache
const cachedUrl = await redis.get(qr:${shortId});
if (cachedUrl) {
// 2. Async Logging (Fire & Forget)
logScanAnalytics(shortId, req);
return res.redirect(cachedUrl);
}
// 3. Database Fallback ...
});
Data Modeling for Analytics
To provide meaningful insights (like "Scans by Device" or "Scans by City"), you need to capture request headers and IP info during the redirect phase.
Conclusion
If you're building a simple contact sharing app, stick to static codes. But for any marketing or enterprise use case where data matters, the dynamic architecture is worth the infrastructure investment.
Top comments (0)