Blog

Chaos engineering for a mobile app: where to start

On staging, the server answers fast and without errors, but for a user on the go every tenth request hangs or ends with a 503. The code paths that handle such responses never run on staging or in autotests, and they break first. Chaos engineering breaks the network on purpose and ahead of time. Here’s a first chaos profile in Microkoi Bench and a list of what to check in the app.

What chaos engineering is, in plain words

Chaos engineering means failures you cause yourself, at a time you choose and under control. The goal is to find a weak spot before a user does.

In large systems, this means shutting down servers and whole zones. A mobile app needs less: it depends on the network and the API. So what you break is the server’s responses: delay them, answer with an error, and not every time but now and then, the way it happens in real life.

Why it’s not just for large systems

  • An error that happens in one request out of twenty can’t be caught by manual testing: a tester goes through the screen three times and sees three successful responses.
  • A mock with an error always answers with an error. It tests the error screen, but not how the app copes when failures are mixed in with successes.
  • Asking the backend to break one endpoint at the right rate is a week-long task, and on a shared staging server it gets in everyone’s way.

Chaos in Bench works in the proxy that the app’s traffic already goes through. Neither the server nor the app code changes.

A first profile: one rule for one endpoint

Example: a food delivery app and its restaurant list screen. The phone’s traffic already goes through the Bench proxy, and HTTPS is decrypted: chaos doesn’t touch connections Bench doesn’t decrypt.

  1. In the “Traffic” section, click “Chaos” on the toolbar, then “Create profile”. Name the profile “Flaky restaurants” and click “Create”.
  2. Open the restaurant list in the app so the requests show up in the “Endpoints” tree. Hover over the api.example.com/v1/restaurants branch, click “⋯” and choose “Chaos”.
  3. Bench adds the rule api.example.com/v1/restaurants/** and opens it in the “Chaos” window. In the “Delay” block, set the “Response” field to “Random”, from 2000 to 5000 ms. The probability in the block header is 30%.
  4. Turn on the “Errors” block, probability 10%. In the “Codes” row, keep 503 and select 500. In the “When” row, keep “Before server”.
  5. Turn on “Apply chaos” and click “Done”.

Now roughly every third request to the restaurants waits 2 to 5 seconds, and every tenth gets a 503 or 500. The app’s other requests go through as usual: the rule only applies to its own branch.

The blocks’ probabilities are independent. A delay and an error can hit the same request, and then the error arrives after the delay. That happens on mobile networks too.

How to tell chaos from a real failure in the traffic

While chaos is on, the Bench title bar shows a “Chaos · Flaky restaurants” badge in every section. But when you dig in, something else matters more: which of the responses in the list is real. An empty screen could come from the server, a mock or chaos, and that decides where to look for the cause.

The first narrow column of the “Traffic” table answers that question; its tooltip is “Response source”. The column marks only the exceptions. For a server response it’s empty, so the paths of all rows start on one line, and marked exchanges stand out at a glance.

IconWho answeredTooltip
EmptyThe server—
Blue cubeA mock or a caseMocked by “Restaurant list”
Orange lightning boltChaos“Slowed down by chaos” or what chaos did
Orange lightning bolt in a blue squareChaos on top of a mockThe mock and a “Chaos on top of the mock: …” line
Yellow pauseThe exchange paused at a breakpoint“Paused at a breakpoint”
Red crossed-out circleThe exchange was canceled at a breakpoint“Canceled at a breakpoint”

The icons differ in shape, not just color. A cell always has one icon, and everything else that happened to the exchange goes on the following lines of the same tooltip. If a mock case answered, the tooltip names it too: Answered by case “No restaurants”, mock “Restaurant list”.

For a tester, the column shows right away which failure chaos caused and which came from the server and deserves a separate report to the backend. For a developer, it shows that the response the screen broke on was spoiled on purpose: the server is fine, and the fix belongs in the app’s error handling.

If chaos answered with an error, the status code is colored in chaos orange, and the tooltip on the code and the lightning bolt says “503 from Bench chaos · before server”. The response body can’t be mistaken for a server response either:

A response from chaos
HTTP/1.1 503 Service Unavailable

Microkoi Bench chaos: 503 Service Unavailable

To keep only the exchanges with a lightning bolt in the list, open “Filters” and check “Chaos” in the “Show only” group. “Without chaos” does the opposite: it removes them from the list, the history and the endpoint tree, leaving only server and mock responses.

“Before server” and “After server”: where retries get tested

When the error happensWhat happensWhat it tests
Before serverThe request doesn’t reach the server, the app gets an error right awayThe error screen and retry. Retrying is safe
After serverThe server handles the request, the app still gets an errorWhether a retry creates a second order

“After server” goes on requests that change something, for example POST /v1/orders. The server creates the order, while the app sees a 500 and offers to retry. If the traffic shows two successful orders after “Retry”, the restaurant gets the same order twice.

The real server response isn’t lost. The “Bench 500 / Server 201” switch above the response in the exchange panel shows both what the app got and what the server answered.

What to check in the app

DisruptionWhat to expectCommon finding
Delay of 2–5 sA loading indicator, the previous list on screen“No restaurants” while loading
503 before serverA clear message and a “Retry” buttonA blank screen with no explanation
500 on POST after serverA retry doesn’t create a second orderTwo orders in the traffic
503 with Retry-AfterNo retry before the given timeFour retries in one second

The “Retry-After” field appears in the “Errors” block when code 429 or 503 is selected. A value of 0 sends the response without the header.

Go through the table and pull the list down to refresh a few times in a row. Each attempt by the app shows up in “Traffic” as a separate row, and the ones chaos spoiled have a lightning bolt: how many retries there were and with what pause is readable without logs or a debugger.

Chaos won’t stay on

  • Bench always starts with chaos off. The selected profile is remembered, but you turn chaos on yourself.
  • The “Turn off” cross on the title bar badge turns chaos off in one click.
  • Profiles are files in the workspace’s chaos/ folder and go into git along with the mocks: a teammate gets the same rules.

A constant error on one request is a job for a mock response; it’s covered in “How to test timeouts and server errors in your app”. Chaos is for when a failure should be rare and random while the other responses stay real.

Build a profile for the most important screen of your app and write to beta@microkoi.com about what it found and which disruption was missing. We read every email.

Microkoi BenchChaosDelays, errors and a slow network

Try it on your own project

The beta is free and needs no sign-up. Download it, pick your project folder and start the proxy — your first requests will show up within minutes.

Version 0.9.6 · macOS, Windows and Linux · no sign-up