Designing an analytics or logging SDK

Mobile system design Senior Kotlin 2.0+ API 24+ Reviewed By Best Latest Apps

Pick the fix

An analytics SDK uploads each event immediately on the calling thread. Apps report jank and ANRs. Fix?

Options
Hint 1 of 1

Should logging an event wait for the network?

Choose an answer, then open Show answer below to check it.

Show answer

Answer: A Queue events to disk and upload batches in the background with WorkManager

Correct. Calls return at once and uploads are batched.

Why not the others?
  • B Upload on a new Thread per event. Too many threads and requests.
  • C Make the API a suspend function. Pushes the problem onto every caller.
  • D Drop all events. Defeats the purpose.

30-second answer

Keep it tiny and safe: a public API that never throws or blocks, events written to a small on-disk queue, and batched uploads with WorkManager under network constraints, with backoff and size limits. Initialise lazily, avoid heavy dependencies, and expose consent controls so nothing is sent before the user agrees. Version the event schema and drop old events when the queue is full.

Practise saying it · 35 s. No recording, just a timer

Design an analytics SDK.

Say your answer out loud, then check which of these points you covered:

  • Non-blocking, never throws
  • Disk queue, batched uploads
  • Lazy init, small
  • Consent
  • Schema versions

Deep dive

Use the host app's Context.applicationContext only.

Ship consumer R8 rules with the SDK.

Avoid starting threads or work at app startup.

Respect privacy laws and Play's Data safety disclosures.

Common mistakes

  • SDK code that can crash the host app.
  • Pulling in large dependencies.
  • Sending data before consent.

Senior take & follow-ups

Reliability, size, privacy and host-app safety.

Follow-up questions

Think of your answer first, then open the hint.

  1. Why must the API never throw?

    Show hint

    A bug in your SDK would crash someone else's app.

  2. How do you limit disk use?

    Show hint

    Cap the queue and drop oldest events.

Similar on iOS: Analytics that respect privacy Similar design; App Tracking Transparency adds a consent prompt on iOS.

Suggest a fix if something here is wrong or out of date.