QA Interview Hub · Knowledge base · Quizzes · Українська

API › The most critical API bugs

Data: pagination, time zones, truncation, caching of private data

Pagination, time zones, silent truncation and caching of private data return 200 with a valid schema but wrong data, so data is compared, not status. Offset pagination on live data duplicates and loses records, so all pages are walked with an insert between requests. Time is tested around midnight in the user's zone, and the cache with two accounts on one URL.

API · Typical bugs

The response is 200 and looks fine, but records are missing from the list. Where did they go?

A client synchronises payments in pages of 100. Between the requests for page one and page two a new payment is created, and the last item of the first page appears again on the second. Another scenario: a report “for yesterday” does not contain an order created at 00:30 Kyiv time. There is no error, the status is 200, the schema is right, and the data is wrong. These bugs are the sneakiest because they cannot be seen without comparing against the expected state.

Four cases: pagination, time zones, silent truncation and encoding, caching of private data.

How it works

Pagination. In offset mode (?page=2&limit=100) the server skips the first 100 records and returns the next ones. If a record was added between requests, everything shifts by one: the last item of page 1 becomes the first on page 2. If a record was deleted, one disappears. Unstable sorting (equal created_at without a second key) also gives duplicates and gaps, because the order of equal records is not guaranteed. Cursor mode is tied to the value of the last returned key, not to a position number, so an insertion does not shift it.

A new record inserted between pages

Typical

Offset

Page 1 returned records 1-2, a new one was added at the start, page 2 returns records 2-3: record 2 twice.

Better

A cursor and a stable key

Page 2 starts after the last key of page 1. The new record does not shift what was already seen.

Figure 1. Offset counts positions, a cursor remembers a key. That is why offset duplicates or loses items on live data.

Example: walking all pages

The test collects ids from all pages and creates a record between requests. Duplicates and gaps are visible at once. Additionally check limit=0, the boundaries of the last page and whether total matches the real count:

test('walking all pages gives no duplicates and no gaps', async ({ request }) => {
  const ids: string[] = [];
  let url: string | null = '/v1/orders?limit=2';
  let inserted = false;

  while (url) {
    const page = await (await request.get(url)).json();
    ids.push(...page.items.map((i: { id: string }) => i.id));
    if (!inserted) {
      await request.post('/v1/orders', { data: { sku: 'new', qty: 1 } }); // between pages
      inserted = true;
    }
    url = page.nextCursor ? '/v1/orders?limit=2&cursor=' + page.nextCursor : null;
  }
  expect(new Set(ids).size).toBe(ids.length); // no duplicates
  // and every order that existed before the walk must be in ids
});

Time zones and day boundaries

The server stores time in UTC, while a user wants a report “for 9 November” in their own zone. If day boundaries are computed in UTC, an order at 23:30 in Kyiv (UTC+2 in winter) is 21:30 UTC of the same day and may be counted, but at 00:30 Kyiv time it is still 22:30 UTC of the previous day, and the order ends up in the “yesterday” report. Check data around midnight in the user’s zone, not in UTC, month and year boundaries, a daylight saving change (a day of 23 or 25 hours) and the format: ISO 8601 / RFC 3339 with or without an offset. A time without an offset is interpreted by the server on its own assumption, which is a source of off-by-one-day errors:

// the user lives in Europe/Kyiv (UTC+2 in winter); 00:30 local is 22:30 UTC of the previous day
test('an order at 00:30 local belongs to that local day', async ({ request }) => {
  const created = await request.post('/v1/orders', {
    headers: { 'X-Timezone': 'Europe/Kyiv' },
    data: { sku: 'a', qty: 1, createdAt: '2026-11-09T00:30:00+02:00' },
  });
  expect(created.status()).toBe(201);

  const report = await request.get('/v1/reports/daily?date=2026-11-09&tz=Europe/Kyiv');
  const ids = (await report.json()).orders.map((o: { id: string }) => o.id);
  expect(ids).toContain((await created.json()).id);
});

The fix: store in UTC and compute day boundaries in the user’s zone.

Silent truncation and encoding

A name longer than 50 characters is stored truncated with no error, an emoji becomes ?, Cyrillic turns into mojibake (UTF-8 read as Windows-1251). The user sees no error but the data is already lost. Check length boundaries (the maximum and the maximum plus one), Unicode (Cyrillic, emoji, combining characters), Content-Type with charset, and the database column limit, which may be smaller than the API validation. The right behaviour is either to store everything or to reject with 400/422, but not to truncate silently:

const limit = 50; // the documented maximum of "name"
for (const [label, name] of [
  ['max', 'a'.repeat(limit)],
  ['max + 1', 'a'.repeat(limit + 1)],
  ['cyrillic', 'Олена-Марія'],
  ['emoji', 'Team 🚀'],
]) {
  test('name: ' + label, async ({ request }) => {
    const res = await request.post('/v1/teams', { data: { name } });
    if (res.status() === 201) {
      const saved = (await (await request.get(res.headers()['location'])).json()).name;
      expect(saved).toBe(name); // stored as sent, not silently cut or mangled
    } else {
      expect([400, 422]).toContain(res.status()); // or rejected with a clear error
    }
  });
}

Caching of private data

User B receives a response meant for A. The cause: a cache (CDN, gateway, reverse proxy) is keyed by URL and ignores the token. Under RFC 9111 a shared cache does not store a response to a request with Authorization unless the response explicitly allows it (public, s-maxage, must-revalidate), but a misconfigured gateway or public on a personal response bypasses that. Check with two accounts on one URL, the Cache-Control headers (private or no-store for personal data), Vary, and also Age and X-Cache (the format depends on the CDN):

test('a personal response is not served to another user from a cache', async ({ request }) => {
  const a = await request.get('/v1/me/orders', { headers: authA });
  const b = await request.get('/v1/me/orders', { headers: authB });

  expect(await b.json()).not.toEqual(await a.json());
  const cc = a.headers()['cache-control'] ?? '';
  expect(cc).toMatch(/private|no-store/);
  expect(a.headers()['age']).toBeUndefined(); // not served from a shared cache
});

One URL for two users through a shared cache

Typical

Cache-Control: public

The gateway stored A’s response under the URL. User B requests the same URL and gets A’s data.

Better

private or no-store

A shared cache does not store a personal response. Each user gets their own.

Figure 2. One wrong directive turns a personal response into one shared by everyone.

Limits and alternatives

  • A pagination test with an insertion catches a shift, but not all stability problems. For large sets also check that the sorting includes a unique key.
  • A time zone test depends on the current date for DST: fix the date in the test and do not rely on the system clock.
  • A cache test on a stage without a CDN proves nothing. Check where the gateway stands, as in production.
  • Silent truncation is sometimes documented as behaviour. Then the bug is in the documentation, not in the code, but the user still has to find out.

Common mistakes

  • Checking only the first page. Duplicates and gaps show up at page boundaries.
  • Testing time in UTC. The defect is visible only at the user’s day boundary.
  • Catching only errors. All four bugs return 200, so you compare data, not status.
  • Not repeating POST and then GET. Truncation is visible only if you compare what was stored with what was sent.
  • Checking the cache with one user. A leak shows up only with two.

Check yourself

A list of 5 records, limit=2. A record was added between the requests for pages 1 and 2. What will the client see with offset pagination?

Answer

The new record is added at the start (sorted by date descending) and everything shifts by one. Page 2 begins with the last record of page 1, so it appears twice. A cursor by key avoids that. The test collects the ids of all pages and checks for no duplicates and no gaps.

A response has Cache-Control: public, max-age=60 on /me/orders. What is dangerous about it?

Answer

A shared cache (CDN, gateway) may serve the stored response to anyone requesting this URL within 60 s. User B may receive A’s orders. For personal data I expect private or no-store. This is a critical leak, and I check it with two accounts.

In an interview. Junior: These are bugs that give no error: the response is 200 but the data is wrong. For example, in pagination a record can appear twice, and time can shift a day. Middle/Senior: Offset duplicates and loses records on live data, so I walk all pages with an insertion between requests and recommend a cursor with a stable key. For time I take midnight in the user’s zone and a daylight saving change, for strings length boundaries and Unicode with a POST then GET check, and for the cache two accounts on one URL and a look at Cache-Control and Vary.

More articles in this chapter