Why one serving is a lie: normalizing a food database to per-100g values

2026-12-03来源 dev.toEnglish

The problem with "one serving"

Ask five people to scoop "one serving" of rice and you get five different numbers. A loosely scooped cup of cooked rice is around 120 g. Pack it down and the same cup holds 180 g or more. That one gesture swings the meal by roughly 80 kcal before you have added anything else to the plate.

Nutrition labels don't save you either. Serving sizes are standardized for labeling, not for your plate. A label might say a serving is 30 g of cereal. Nobody eats 30 g of cereal.

When we started building the food database behind Alkemos, this was the first data-modeling decision we had to get right.

The decision: everything per 100 g

Every food in the database is stored with one normalized record: calories, protein, carbs and fat per 100 grams. No "servings", no "cups", no "pieces" as the canonical unit.

The math then becomes trivially exact:

nutrients(quantity) = per_100g_value * quantity / 100 

Scaling is linear for macros, so a 170 g chicken breast is just the per-100g row times 1.7. No rounding drift, no lookup tables of arbitrary serving definitions.

Why per 100 g and not per serving

  • It's what most nutrition labels already use. EU and most non-US labels are per 100 g or 100 ml, so imported data maps directly.
  • It composes. A recipe is a list of gram quantities. A meal is a list of foods. A day plan is a list of meals. The same per-100g rows roll up cleanly at every level.
  • It survives UX changes. If the app later wants to display "cups" for American users, that's a presentation-layer conversion, not a data problem.

The edge cases we had to handle

Raw vs cooked. Rice roughly triples in weight when it absorbs water. Storing only the raw row makes cooked portions look three times more caloric than they are. We store raw and cooked as separate entries, which doubles some rows but keeps the math honest.

Liquids. Milliliters and grams are close enough for water-like liquids, but not for oil or honey. Those get gram-based entries with density notes.

Branded items. Manufacturer labels occasionally disagree with generic database entries. The branded label wins for that product.

What this buys the planner

Because every row is per 100 g, the meal planner can generate a full day of eating, breakfast to dinner, where every ingredient is a gram quantity and the day's macros add up exactly to the target. The database now holds 8,162+ foods, and the ready-made diet plans it powers are written entirely in grams.

That was the real payoff: one boring normalization decision, made early, is the reason "eat 2,000 kcal" can turn into a precise shopping list instead of a vague aspiration.

Disclosure: I'm the founder of Alkemos, the platform this database powers. The food library and diet plans are free to browse, no signup required.

原文:https://www.a8q9.cn/en/article/why-one-serving-is-a-lie-normalizing-a-food-database-to-per-100g-values-3e7090.html

相关文章