call(back)

Design a Logging Library for Web and Mobile Clients

Design a logging library that runs inside web and mobile applications and ships logs to a backend. The application must never be slowed or blocked by logging, devices go offline, and call volume rises with the user base.

Cover the API, buffering and flushing, behaviour when the device is offline, how the library behaves under pressure when logs arrive faster than they can be sent, and what the backend receives.

Hints

Hint 1

log() appends to a bounded in-memory buffer and returns immediately; a background flush sends batches when the buffer reaches a size or an interval elapses.

Hint 2

Persist the buffer to local storage when offline and retry with backoff; cap the on-disk size too.

Hint 3

Under pressure, choose explicitly: drop oldest, drop newest, or sample by level. Blocking the app is never acceptable.

Asked at