溯源的痛点:不只是”贴个码”
鲜生记是一家做高端生鲜的连锁品牌,主打”从产地到餐桌”的品质承诺。但他们遇到了一个很现实的问题:消费者不信。
你说你的牛肉是澳洲进口的,有什么证据?你说你的蔬菜是有机种植的,怎么证明?出了食品安全问题,能不能查到是哪一批、从哪来的?
很多企业的做法是:给商品贴个二维码,消费者扫码能看到一些信息。但仔细看就会发现,这些所谓的”溯源码”问题很多:
- 信息是静态的:扫码看到的就是一张产地图片+一段文字介绍,是提前录好的,跟实际批次没关系;
- 数据是断的:只能看到产地信息,中间的运输、仓储、门店环节全是黑箱;
- 容易被复制:二维码谁都能扫、谁都能复制,假货也贴个一样的码,消费者根本分不清;
- 没有闭环:扫了就扫了,企业不知道谁扫了、什么时候扫的、消费者有什么反馈。
说白了,很多溯源系统就是个”摆设”,给消费者看个心理安慰,真出了问题啥用没有。
那真正的一物一码溯源系统应该是什么样的?我们给鲜生记做的方案,核心是四个字:全链路闭环。
整体架构:一条链,三个端
整个系统的架构可以概括为”一条数据链,三个终端入口”:
┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐
│ 产地/工厂 │ │ 仓储物流 │ │ 门店终端 │ │ 消费者 │
│ 赋码上报 │ │ 扫码流转 │ │ 出入库 │ │ 扫码查询 │
└─────┬────┘ └─────┬────┘ └─────┬────┘ └─────┬────┘
│ │ │ │
└─────────────┴──────┬──────┴─────────────┘
│
┌──────┴──────┐
│ 业务中台 │
│ 码服务/数据 │
│ 存储/分析 │
└─────────────┘一条数据链:每一件商品从出生到被消费,每一个环节的数据都被记录下来,形成一条完整的数据链。
三个终端入口:
- 生产端:产地/工厂赋码,把商品基础信息写进去;
- 流转端:仓储、物流、门店各环节扫码,记录流转状态;
- 消费端:消费者扫码查询,同时把消费者行为数据回传给企业。
下面我们从”码”开始,逐层拆解这个架构。
第一层:码的设计——不只是个二维码
很多人觉得”一物一码”不就是生成个二维码贴上吗?没那么简单。码的设计直接决定了整个系统的安全性和可用性。
1. 码的类型:动态码 vs 静态码
静态码就是内容固定的二维码,扫出来永远是同一个页面。这种码的问题是:容易被复制,假货贴个一样的码你根本分不清。
我们用的是动态码:每个码扫出来的内容是动态生成的,而且第一次扫和第二次扫看到的不一样。
具体来说:
- 每个码有一个唯一的ID,和商品绑定;
- 消费者第一次扫码,会显示”首次查询”的标记,还有查询时间和地点;
- 第二次再扫,会显示”这是第N次查询”,并且把前几次的查询记录都列出来。
这样一来,如果消费者买到的商品,扫码显示”已经被查询过5次”,那就要小心了——很可能是假货。
2. 码的安全:防伪造、防篡改
码本身怎么防伪造?我们用了几层机制:
- 加密生成:码的ID不是连续的数字,而是加密生成的随机字符串,无法被猜测和批量伪造;
- 后台校验:每次扫码都要请求后台校验,码是否有效、是否被注销、查询次数多少,都是后台说了算;
- 物理防伪:对于高价值商品,可以结合防伪标签(比如揭开留底、激光防伪),二维码印在防伪层下面,揭开才能扫,扫过即失效。
3. 码的层级:箱码 + 盒码 + 单品码
生鲜商品有个特点:批次管理很重要。一箱里面有10盒,一盒里面有20个单品,如果每个单品都要赋码,成本太高。
我们的方案是三级码体系:
- 箱码:外箱贴一个码,代表整箱,用于物流和仓储环节;
- 盒码:每盒贴一个码,代表一盒,用于门店收货和销售环节;
- 单品码:高价值单品(比如进口牛排、有机蔬菜)贴单品码,消费者扫码看详细溯源信息。
三级码之间是关联的:扫箱码能看到里面有多少盒、每盒的码是什么;扫盒码能看到它属于哪个箱、从哪来的。这样既保证了溯源能力,又控制了成本。
第二层:数据采集——每个环节都”说话”
有了码之后,接下来就是在各个环节采集数据,把商品的”一生”记录下来。
1. 生产/采购环节:赋码 + 基础信息
在产地或者工厂,商品生产出来的时候就赋码,同时录入基础信息:
- 产地信息:哪个农场、哪个批次、什么时候采摘/生产的;
- 品质信息:等级、规格、重量;
- 检测信息:农残检测报告、质检报告(可以上传图片或PDF);
- 责任人:谁负责这个批次。
这一步可以用PDA手持终端操作,也可以用小程序——工人拿手机扫码就能录入,不需要专门的设备。
2. 仓储物流环节:扫码 + 流转记录
商品从产地发往仓库、从仓库发往门店,每一次流转都要扫码记录:
- 入库:扫箱码,记录入库时间、仓库位置、入库数量;
- 出库:扫箱码,记录出库时间、发往哪个门店、承运人;
- 运输:如果有温控要求(比如冷链),运输车上的温度传感器会自动上报温度数据,和运输记录绑定。
这里有个技术细节:物流环节不一定有网络。比如长途运输的时候,司机在高速上没信号。所以我们的PDA和小程序都支持离线操作——本地先存着,有网了再同步。中台侧做幂等处理,保证数据不重复。
3. 门店环节:收货 + 销售 + 售后
到了门店,环节更多:
- 收货:扫箱码/盒码,确认收货,记录收货时间、收货人、收货时的温度(如果是冷链商品);
- 上货:从仓库搬到货架,扫一下,记录上货时间;
- 销售:POS系统和中台对接,卖出的时候自动记录销售时间、门店、价格;
- 报损:过期或者损坏的商品,扫码报损,记录原因。
这些数据有的是人工扫码录的,有的是系统自动同步的。关键是:每一个环节的数据,都要和那个唯一的码绑定起来。
4. 消费环节:消费者扫码 + 行为数据
最后,消费者买了商品,扫码看溯源信息。这一步不只是”给消费者看信息”,更是数据闭环的最后一环——把消费者行为数据回传回来。
消费者扫码的时候,我们能拿到这些信息:
- 谁扫的(微信openid,匿名化处理);
- 什么时候扫的;
- 在什么地方扫的(地理位置);
- 看了哪些信息、看了多久;
- 有没有点击”联系客服""举报问题”等按钮。
这些数据非常有价值:
- 防伪验证:如果同一个码被扫了很多次,而且地点分散,很可能是假货;
- 消费者洞察:哪些产地的信息消费者最关注?哪些商品的扫码率最高?
- 精准营销:扫过码的消费者,可以推送相关的优惠券或者会员权益。
第三层:中台数据存储——海量数据怎么存
一物一码系统的数据量是很大的。假设鲜生记每天卖10万件商品,每件商品平均经过5个环节,每个环节产生1条记录,那每天就是50万条记录,一年就是近2亿条。
这么大的数据量,怎么存?怎么查?
我们的存储架构是这样的:
┌─────────────────────────────────────────┐
│ 接入层:API网关 │
├─────────────────────────────────────────┤
│ 服务层:码服务 │
│ 生成/校验/查询/关联/统计 │
├──────────┬──────────┬──────────────────┤
│ 关系数据库 │ 时序数据库 │ 对象存储 │
│ (基础信息) │ (流转记录) │ (检测报告/图片) │
│ PostgreSQL│ TDengine │ S3/MinIO │
└──────────┴──────────┴──────────────────┘1. 关系数据库:存基础信息
商品的基础信息(名称、规格、产地、批次等)存在关系数据库里。这些数据量不大,但是查询频繁,需要事务保证一致性。
2. 时序数据库:存流转记录
每个环节的扫码记录、传感器上报数据,这些都是时序数据——带时间戳、数据量大、写多读少、按时序查询。
这些数据存在时序数据库(我们用的是TDengine)里。时序数据库针对这种场景做了优化,写入速度快、压缩比高、查询性能好。
3. 对象存储:存文件
检测报告、产地图片、视频这些文件,存在对象存储里。数据库里只存文件的URL,需要的时候再去取。
4. 查询优化:预聚合 + 缓存
消费者扫码查询的时候,要把整个链路的数据都查出来,如果每次都实时查多个库,速度会很慢。
我们的做法是:
- 预聚合:商品销售之后,后台异步把整个链路的数据汇总好,存在一个查询表里;
- 缓存:热门商品的溯源信息,存在Redis缓存里,扫码的时候直接从缓存取,毫秒级响应。
这样消费者扫码体验就很好,不会等半天。
第四层:数据闭环——从”能查”到”能用”
很多溯源系统做到”消费者能扫码看到信息”就结束了。但我们认为,这才只是开始。真正的价值在于数据闭环——数据不仅能查,还能用来做分析、做决策、做营销。
1. 防伪与打假
通过扫码数据,可以发现异常:
- 同一个码在短时间内被多次查询,而且地点分散;
- 查询地点和商品销售区域不符(比如北京的商品,码在广东被扫了);
- 某个批次的扫码率异常高(正常扫码率可能是5%,突然变成50%,可能有问题)。
发现异常之后,可以自动告警,市场部门可以跟进调查。
2. 供应链优化
通过全链路数据,可以分析供应链效率:
- 每个环节的平均耗时是多少?哪个环节最慢?
- 运输过程中温度超标的情况多不多?是哪个承运商的问题?
- 门店报损率是多少?什么原因导致的?
找到瓶颈,就能针对性优化。鲜生记上线系统后,通过数据分析发现某条线路的运输温度超标率比较高,换了承运商之后,报损率降了15%。
3. 消费者运营
扫码的消费者,都是真实的、买过你商品的人,这是非常精准的用户群体。
你可以:
- 引导关注公众号、注册会员;
- 根据购买的商品推荐相关产品;
- 做扫码抽奖、积分等活动,提升复购;
- 收集消费者反馈,改进产品和服务。
鲜生记上线后,通过扫码引导注册的会员,转化率比普通渠道高3倍——因为消费者刚买了你的产品,对你有信任,这时候转化效果最好。
落地效果:不只是溯源
鲜生记的一物一码系统上线半年后:
- 消费者信任度提升:有溯源码的商品,销量比没有的高20%以上;
- 报损率下降:通过全链路数据分析,找到了供应链的几个瓶颈点,整体报损率下降了12%;
- 会员增长:扫码注册会员超过10万人,复购率提升15%;
- 食品安全保障:有一次某批次蔬菜检测出农残超标,通过系统两个小时内就定位到了涉及的门店和商品,全部下架,没有造成食品安全事故。
结语
一物一码,听起来是个很简单的概念——不就是给商品贴个码吗?但真正要做好,要做到”全链路闭环”,里面的门道很多。
从码的安全设计,到各环节的数据采集,到海量数据的存储和查询,再到数据的分析和应用——每一层都有技术细节,每一层都有业务价值。
溯源不是目的,通过溯源建立信任、优化供应链、连接消费者,才是真正的价值所在。
如果你也在考虑做一物一码,不要只想着”贴个码能查就行”。多想想:数据能不能闭环?闭环之后能用来做什么?想清楚这些,你的投入才会有更大的回报。
The Pain Point of Traceability: It’s Not Just “Sticking a Code”
FreshStory is a premium fresh food chain brand, built on the promise of “from farm to table” quality. But they faced a very real problem: consumers didn’t believe them.
You say your beef is imported from Australia — what’s the proof? You say your vegetables are organically grown — how do you prove it? If there’s a food safety issue, can you trace which batch it came from and where it originated?
Many companies’ approach: stick a QR code on the product, consumers scan it and see some information. But look closely, and these so-called “traceability codes” have many problems:
- Static information: Scanning shows a picture of the origin + some text description — pre-recorded, unrelated to the actual batch.
- Broken data chain: You only see origin information; transportation, warehousing, and store stages are all black boxes.
- Easily copied: Anyone can scan the QR code, anyone can copy it. Counterfeit products stick the same code — consumers can’t tell the difference.
- No closed loop: They scan and that’s it. The company doesn’t know who scanned it, when, or what feedback consumers have.
Frankly, many traceability systems are just “window dressing” — giving consumers psychological comfort, but useless when real problems arise.
So what should a real “one item, one code” traceability system look like? The solution we built for FreshStory centers on four words: end-to-end closed loop.
Overall Architecture: One Chain, Three Terminals
The system architecture can be summarized as “one data chain, three terminal entry points”:
┌──────────┐ ┌──────────┐ ┌──────────┐ ┌──────────┐
│Origin/ │ │Warehouse/│ │Store │ │Consumer │
│Factory │ │Logistics │ │Terminal │ │ │
│Code & │ │Scan & │ │In/Out │ │Scan & │
│Report │ │Transfer │ │Bound │ │Query │
└─────┬────┘ └─────┬────┘ └─────┬────┘ └─────┬────┘
│ │ │ │
└─────────────┴──────┬──────┴─────────────┘
│
┌──────┴──────┐
│ Biz Middle │
│ Platform │
│Code Service/│
│Storage/ │
│Analytics │
└─────────────┘One data chain: Every product’s journey from creation to consumption is recorded at each stage, forming a complete data chain.
Three terminal entry points:
- Production side: Origin/factory assigns codes, records product base information.
- Flow side: Warehousing, logistics, store stages scan codes, record transfer status.
- Consumer side: Consumers scan to query, and consumer behavior data flows back to the company.
Let’s break down this architecture layer by layer, starting with the “code” itself.
Layer 1: Code Design — It’s Not Just a QR Code
Many people think “one item, one code” is just generating a QR code and sticking it on. It’s not that simple. Code design directly determines the security and usability of the entire system.
1. Code Type: Dynamic vs. Static
A static code has fixed content — scanning it always shows the same page. The problem: easily copied. Counterfeit products stick the same code and you can’t tell the difference.
We use dynamic codes: each code’s content is dynamically generated, and the first scan looks different from subsequent scans.
Specifically:
- Each code has a unique ID, bound to the product.
- First scan by a consumer shows a “First Query” marker, with query time and location.
- Second scan shows “This is the Nth query” and lists all previous query records.
This way, if a consumer buys a product and scanning shows “already queried 5 times,” they should be careful — it might be counterfeit.
2. Code Security: Anti-Forgery, Anti-Tampering
How do you prevent code forgery? We use several layers:
- Encrypted generation: Code IDs aren’t sequential numbers — they’re encrypted random strings that can’t be guessed or batch-forged.
- Backend verification: Every scan requests backend verification — code validity, cancellation status, query count — all determined by the backend.
- Physical anti-counterfeiting: For high-value products, combine with anti-counterfeit labels (e.g., scratch-off, laser hologram). The QR code is printed under the anti-counterfeit layer — you scratch to scan, and once scanned, it’s invalidated.
3. Code Hierarchy: Case Code + Box Code + Item Code
Fresh food has a characteristic: batch management matters. A case contains 10 boxes, a box contains 20 items. If every single item needs a code, costs are too high.
Our solution is a three-level code system:
- Case code: One code on the outer carton, representing the whole case — used in logistics and warehousing.
- Box code: One code per box, representing a box — used for store receiving and sales.
- Item code: High-value items (e.g., imported steak, organic vegetables) get individual codes for detailed traceability.
The three levels are linked: scan a case code and see how many boxes are inside and what each box’s code is. Scan a box code and see which case it belongs to and where it came from. This ensures traceability while controlling costs.
Layer 2: Data Collection — Every Stage “Speaks”
With codes in place, the next step is collecting data at each stage, recording the product’s entire “lifetime.”
1. Production/Procurement Stage: Code Assignment + Base Info
At the origin or factory, codes are assigned when products are produced, and base information is entered:
- Origin info: which farm, which batch, when harvested/produced.
- Quality info: grade, specifications, weight.
- Inspection info: pesticide residue reports, quality inspection reports (images or PDFs can be uploaded).
- Responsible person: who’s in charge of this batch.
This step can be done with PDA handheld terminals, or with a mini program — workers scan with their phones and enter data, no specialized equipment needed.
2. Warehousing & Logistics Stage: Scan + Transfer Records
As products move from origin to warehouse, from warehouse to store, each transfer is scanned and recorded:
- Inbound: Scan case code, record inbound time, warehouse location, quantity.
- Outbound: Scan case code, record outbound time, destination store, carrier.
- Transport: For temperature-controlled goods (e.g., cold chain), temperature sensors in the truck automatically report temperature data, bound to the transport record.
One technical detail: logistics stages don’t always have network access. For example, during long-haul transport, drivers on highways have no signal. So our PDAs and mini program both support offline operation — store locally first, sync when network is available. The middle platform uses idempotent processing to ensure no duplicate data.
3. Store Stage: Receiving + Sales + After-Sales
At the store, there are more stages:
- Receiving: Scan case/box code, confirm receipt, record time, receiver, temperature at receipt (for cold chain goods).
- Shelving: Moving from backroom to shelf — scan to record shelving time.
- Sales: POS system integrates with the middle platform — when sold, automatically records sale time, store, price.
- Spoilage: Expired or damaged products — scan for spoilage report, record reason.
Some data is entered by manual scanning, some synced automatically by systems. The key: every stage’s data is bound to that unique code.
4. Consumer Stage: Scan + Behavior Data
Finally, consumers buy the product and scan to see traceability info. This step isn’t just “showing information to consumers” — it’s the final link in the data closed loop: sending consumer behavior data back.
When consumers scan, we capture:
- Who scanned (WeChat openid, anonymized).
- When they scanned.
- Where they scanned (geolocation).
- What information they viewed, how long.
- Whether they clicked “contact customer service,” “report issue,” etc.
This data is extremely valuable:
- Anti-counterfeiting verification: If the same code is scanned many times in scattered locations, it’s likely counterfeit.
- Consumer insights: Which origin info do consumers care about most? Which products have the highest scan rates?
- Precision marketing: Consumers who scanned can receive relevant coupons or membership benefits.
Layer 3: Middle Platform Data Storage — Handling Massive Data
A “one item, one code” system generates a lot of data. Suppose FreshStory sells 100,000 items daily, each item goes through an average of 5 stages, each stage generates 1 record — that’s 500,000 records per day, nearly 200 million per year.
With that much data, how do you store it? How do you query it?
Our storage architecture looks like this:
┌─────────────────────────────────────────┐
│ Access Layer: API Gateway │
├─────────────────────────────────────────┤
│ Service Layer: Code Service │
│ Generate/Verify/Query/Link/Stats │
├──────────┬──────────┬──────────────────┤
│Relational│Time-Series│ Object Storage │
│ DB │ DB │ (Reports/Images)│
│PostgreSQL│ TDengine │ S3/MinIO │
└──────────┴──────────┴──────────────────┘1. Relational Database: Base Information
Product base information (name, specs, origin, batch, etc.) lives in a relational database. This data volume isn’t large, but queries are frequent, and transactional consistency is needed.
2. Time-Series Database: Flow Records
Scan records from each stage, sensor-reported data — these are all time-series data: timestamped, high volume, write-heavy read-light, queried by time range.
This data goes into a time-series database (we use TDengine). Time-series databases are optimized for this scenario: fast writes, high compression ratio, good query performance.
3. Object Storage: Files
Inspection reports, origin photos, videos — these files go into object storage. The database only stores the file URL; fetch when needed.
4. Query Optimization: Pre-Aggregation + Caching
When consumers scan to query, they need the entire chain’s data. If you query multiple databases in real-time every time, it’s slow.
Our approach:
- Pre-aggregation: After a product is sold, the backend asynchronously aggregates the entire chain’s data into a query table.
- Caching: Traceability info for popular products lives in Redis cache. Scanning retrieves directly from cache — millisecond response.
This gives consumers a great scanning experience — no waiting.
Layer 4: Data Closed Loop — From “Queryable” to “Useful”
Many traceability systems stop at “consumers can scan and see information.” But we believe that’s just the beginning. The real value lies in the data closed loop — data isn’t just queryable, it can be used for analysis, decision-making, and marketing.
1. Anti-Counterfeiting & Anti-Fraud
Through scan data, you can spot anomalies:
- The same code queried multiple times in a short period, in scattered locations.
- Query locations don’t match the product’s sales region (e.g., a Beijing product’s code scanned in Guangdong).
- Abnormally high scan rates for a batch (normal might be 5%, suddenly 50% — could be a problem).
When anomalies are detected, automatic alerts trigger, and the marketing team can investigate.
2. Supply Chain Optimization
With end-to-end data, you can analyze supply chain efficiency:
- What’s the average time at each stage? Which stage is the bottleneck?
- How often do temperature excursions happen during transport? Which carrier is the problem?
- What’s the store spoilage rate? What causes it?
Find the bottlenecks, optimize accordingly. After FreshStory launched the system, data analysis revealed higher temperature excursion rates on one route. After switching carriers, spoilage dropped 15%.
3. Consumer Operations
Consumers who scan are real people who bought your product — a very precise user group.
You can:
- Guide them to follow your official account, register as members.
- Recommend related products based on what they bought.
- Run scan-to-win raffles, points programs, to boost repurchase.
- Collect consumer feedback to improve products and service.
After launch, members registered via scanning had 3x higher conversion rate than other channels — because consumers just bought your product, they trust you, and conversion is best at that moment.
Results: More Than Just Traceability
Six months after FreshStory’s “one item, one code” system launched:
- Consumer trust improved: Products with traceability codes sold 20%+ more than those without.
- Spoilage rate dropped: Through supply chain data analysis, several bottlenecks were identified, and overall spoilage dropped 12%.
- Member growth: Over 100,000 members registered via scanning, repurchase rate up 15%.
- Food safety assurance: Once, a batch of vegetables tested positive for pesticide residues. Using the system, they identified affected stores and products within two hours and pulled everything — no food safety incident occurred.
Closing Thoughts
“One item, one code” sounds like a simple concept — isn’t it just sticking a code on a product? But doing it right, achieving an “end-to-end closed loop,” involves many layers.
From secure code design, to data collection at every stage, to storing and querying massive data, to analyzing and applying the data — every layer has technical details, every layer has business value.
Traceability isn’t the goal. Building trust through traceability, optimizing the supply chain, connecting with consumers — that’s where the real value lies.
If you’re considering a “one item, one code” system, don’t just think “stick a code so people can query it.” Think bigger: can the data form a closed loop? What can you do with that closed loop? Figure those out, and your investment will pay off much more.