Introduction

We handle a lot of traffic, so we keep looking for ways to make our systems more efficient. One question led us to look closer at our application programming interface (API) responses: how much data were we sending more than once?

In some merchant-menu responses, multiple items shared the same size choices and add-ons, but we repeated those options under each item. Gzip reduced the bytes sent over the network, yet Android and iOS clients still had to parse each copy after decompression.

Could we send those shared options once while preserving the response model our mobile business logic depends on? What would that change do to the traffic we handle?

Problem statement

To see where payload reduction could have the greatest impact, we examined production traffic. Response sizes followed a long-tailed distribution: most requests were small, while a much smaller group of large responses consumed a disproportionate share of bandwidth.

To estimate the opportunity, we matched legacy- and optimised-format responses for the same merchant menus. For each matched group, we established a representative gzip-size baseline from legacy responses between 2 KiB and 10 MiB, then weighted that baseline by the group’s request volume during the optimised period. This gives a request-weighted estimate for matched menus, rather than a population-wide average.

Merchant groups with an average legacy response of at least 100 KiB accounted for about 16% of matched optimised request events but around 80% of estimated savings. We then examined whether their larger responses contained required business data or repeated structures that could be sent once.

Bar chart of request share versus estimated savings share by legacy response size bucket
Figure 1. Merchant groups with larger average legacy responses account for a disproportionate share of estimated traffic savings.
Table of average gzip size and traffic reduction by legacy size bucket
Figure 2. Average gzip size and traffic reduction by legacy size bucket for matched merchant menus.

Repeated objects in nested menu data

Production data showed that complex menus often repeated the same modifier groups and modifier definitions across multiple items. In the legacy response, each item included an inline copy of the shared configuration. These duplicates increased payload size without adding menu information for the client.

For a drink, “Choose size” is a modifier group, and “Small” and “Large” are its modifiers (the individual choices within that group). A menu item is the product being ordered; different drinks can share the same size-selection group.

Legacy response

{ "items": [
    { "id": "item-1", "modifierGroups": [
        { "id": "group-1", "name": "Choose size",  "modifiers": [
            { "id": "small", "name": "Small" }, { "id": "large", "name": "Large" }
          ]}
      ]},
    { "id": "item-2", "modifierGroups": [
        { "id": "group-1",  "name": "Choose size", "modifiers": [
            { "id": "small", "name": "Small" }, { "id": "large", "name": "Large" }
          ]}
      ]}
  ]}

Illustrative example. The same modifier group and modifier definitions are serialised under both items.

Solving the problem

Choosing a response representation

Gzip was already enabled and compressed repeated byte patterns, but the decompressed response still contained duplicate objects that clients had to parse. Changing the API schema or removing fields would have expanded the migration and testing effort.

Instead, we changed how the response represents shared data. The backend normalises repeated entities into reusable pools, and menu items reference those entities rather than embedding duplicate definitions. Android and iOS clients reconstruct the legacy object graph at the network boundary, before existing business logic runs. The wire format changes, but the application-facing model remains the same.

Diagram of legacy inline modifier groups versus a normalised entity pool referenced by item IDs
Figure 3. Shared modifier groups (such as “Choose size”) and their choices are stored once; menu items reference them by identifier.

Normalising the response

The backend extracted repeated objects into entity pools and replaced inline copies with references. In this API, the transformation applied to categories[].items[].modifierGroups and their nested modifiers. categories[].elementCards[].item remained inline.

Normalised response

{ "entities": {
    "modifierGroups": {
       "group-1": { "id": "group-1", "name": "Choose size",
            "modifierIds": ["small", "large"] }
    },
    "modifiers": {
      "small": { "id": "small", "name": "Small" },
      "large": { "id": "large", "name": "Large" }
    }
  },
  "items": [
    { "id": "item-1", "modifierGroupIds": ["group-1"] },
    { "id": "item-2", "modifierGroupIds": ["group-1"] }
   ] }

Illustrative example. The entity names are fictional and were created to show how responses are normalised.

Each unique entity is sent once. Items retain references, so relationships remain unchanged while repeated definitions no longer dominate the payload.

Deduplication compared the business identifier (ID) and a fingerprint of response-visible fields. When all occurrences under one ID had the same fingerprint, the original ID remained the key. When one ID had multiple visible versions, the emitted keys distinguished those versions; repeated identical versions reused one entity.

Menus are one example. The same pattern can apply to catalogues, product listings, order histories, recommendation results, and search results when many parents share the same nested entities.

Reconstructing the legacy model on mobile

The mobile clients reconstruct the legacy response shape from the optimised payload at the network boundary, before existing business logic runs. If reconstruction or reference validation fails, or the canonical-hash check fails when a hash is present, the client makes one additional request with the optimised format disabled. This gives us a clear fallback path without user-experience disruption if mobile parsing fails. Network errors and failures parsing the legacy response follow the existing request error path.

A backend fallback is separate from this client retry: the server returns a legacy-format body, which the client parses with its legacy parser. In either path, application logic continues to receive the established model.

Flowchart of the mobile compatibility layer restoring the legacy model, with a retry to the legacy format on failure
Figure 4. The compatibility layer rebuilds the legacy response shape before application logic runs. A reconstruction or validation failure triggers one retry with the optimised format disabled.

Correctness and rollout

Correctness took more work than compression

Once we identified the repeated entities, representing them once was relatively straightforward. The harder part was proving that the backend and the mobile clients preserved the same response semantics.

We tested reference integrity, semantic equivalence between the original and reconstructed JavaScript Object Notation (JSON), and typed-model restoration on each mobile platform. We also exercised recovery from optimised-response failures and monitored parse failures, retries, latency, and client resource use.

When the canonical-hash header was present, we canonicalised the reconstructed legacy JSON and checked its hash against the backend-provided value. Canonicalisation normalises serialisation differences such as object-key order and equivalent escaping, but it cannot prove that a typed client model preserves every field. We therefore tested hash validation and typed-model restoration separately, including null and default handling.

The response format is part of the API contract. The backend and mobile clients can use different implementations, provided they preserve the same meaning.

Rolling out safely

We enabled the optimised format gradually, with each rollout step gated by client capability, backend enablement, and production telemetry. We tracked adoption, response-size reduction, parsing and reconstruction failures, recovery to the legacy format, request latency, and mobile central processing unit (CPU) time, wall-clock time, and memory use.

We measured duration per logical menu request. If the client retried using the legacy format, the duration included both attempts. This captured the retry’s impact alongside the network savings from smaller payloads and the device resources used to reconstruct the legacy model.

Results

Gateway traffic and payload impact

Metric All-platform API Gateway comparison
Average response bytes per request lower by approximately 20%

We compared two seven-day API Gateway observation windows across Android and iOS, using the same response-byte collection scope.

Matched traffic and request duration

Merchant-matched request-duration observations

95th percentile (P95) request duration decreased in all reported Android and iOS comparison cohorts. Median (P50) duration decreased in most cohorts.

These results are request-weighted summaries of per-merchant percentiles from historical three-day comparisons. Observation windows and rollout stages differ across cohorts, so they should not be interpreted as a single overall P50 or P95.

Android matched wire-byte estimate

A merchant-matched Android comparison estimated a 38.1% traffic-weighted reduction in client-observed gzip wire bytes relative to a legacy-format reference. Merchant groups with an average legacy response of at least 50 KiB contributed 89.4% of estimated savings. The estimate covers matched traffic served in the optimised format. It is separate from the all-platform API Gateway comparison and is not extrapolated to iOS.

Client reconstruction and reliability

Reconstruction work at P95

Platform CPU Wall time Memory
Android +105.9 ms +203.9 ms +8.07 MB
iOS +2.3 ms +2.6 ms +0.55 MB

These are seven-day merchant-matched comparisons of the frontend parse-and-restore span, not total device work or end-to-end request latency.

Parsing failures and recovery

During the observation period, the optimised client path had a parsing failure rate of 0.00023%, with no backend-fallback events recorded. Legacy-format recovery retries following optimised parsing failures or hash mismatches succeeded in approximately 99.6% of recorded retry events. Parsing failures and recovery retries use separate telemetry scopes.

Lessons and applicability

What we learned

Measure savings against client work

Use response-size and duplication data to identify where normalisation can save meaningful traffic. Measure the client-side reconstruction work alongside those savings; smaller payloads do not automatically mean less client work.

Validate typed models, not only JSON

Semantic JSON checks confirmed that reconstructed responses preserved their meaning, but could not prove that Android and iOS models retained every field. We paired them with platform-specific parser and model tests, including null and default handling.

Design recovery before rollout

Legacy-format retries, telemetry, and feature gates were designed alongside the new format. They supported a gradual rollout and allowed us to disable the optimised path without waiting for a mobile release.

When this pattern works

Entity-based response normalisation is a good fit for large collection APIs where many parent records share nested objects, entity IDs are stable or a content fingerprint can distinguish versions, and clients can rebuild the legacy response before business logic runs. It is less useful for flat or small responses, low-duplication data, or clients that cannot reliably reconstruct the original shape.

For the merchant-menu API, we weighed estimated traffic savings against mobile reconstruction work. The trade-off depends on response size, duplication, device characteristics, and request mix, so it should be evaluated for each API rather than assumed from the data shape alone.

What’s next

We are assessing other large collection APIs using the same sequence: measure the response-size distribution, confirm that repeated nested entities drive the largest responses, and verify that clients can safely reconstruct and validate the existing model. We will apply normalisation only when the expected transfer savings justify the client-side reconstruction work.

Join us

Grab is Southeast Asia’s leading superapp, serving over 900 cities across eight countries (Cambodia, Indonesia, Malaysia, Myanmar, the Philippines, Singapore, Thailand, and Vietnam). Through a single platform, millions of users access mobility, delivery, and digital financial services, including ride-hailing, food delivery, payments, lending, and digital banking via GXS Bank and GXBank. Founded in 2012, Grab’s mission is to drive Southeast Asia forward by creating economic empowerment for everyone while delivering sustainable financial performance and positive social impact.

Powered by technology and driven by heart, our mission is to drive Southeast Asia forward by creating economic empowerment for everyone. If this mission speaks to you, join our team today!