Design own Crashlytics kind of System for Android

kapil sharma
3 min readNov 27, 2017

--

Use Cases:

  1. Catch any exception comes in your application
  2. Send it to your server
  3. UI(Not Applicable)/API (Ofcourse)

Constraints:

Amount of Traffic: 1 Million Request per day which turns into 12 request/sec

Amount of Data: Let’s consider that we need to keep crash report for about an year in our DB. Crash report is more of a text which size depend upon text data by client to server but for simplicity we can consider that 1 request will store somewhere 1KB.

1KB = 1 request

1MB = 1024 request

1GB = 1024 * 1024 = 1M request(In single day)

365 GB = 1 Year

Abstract Design:

HLD: Because this question is more of Client end and not from server end. Hence i am not focusing more on server end. However i have found interesting HLD on internet and sharing it here:

Low Level Design: Here we are discussing more about implementation on Android End.

Java actually handles uncaught exceptions according to the thread in which they occur. When an uncaught exception occurs in a particular thread, Java looks for what is called an uncaught exception handler, actually an implementation of the interface UncaughtExceptionHandler. The latter interface has a method handleException(), which the implementer overrides to take appropriate action, such as printing the stack trace to the console. As we’ll see in a moment, we can actually install our own instance of UncaughtExceptionHandler to handle uncaught exceptions of a particular thread, or even for the whole system.

The specific procedure is as follows. When an uncaught exception occurs, the JVM does the following:

  • it calls a special private method, dispatchUncaughtException(), on the Thread class in which the exception occurs;
  • it then terminates the thread in which the exception occurred1.

The dispatchUncaughtException method, in turn, calls the thread’s getUncaughtExceptionHandler() method to find out the appropriate uncaught exception handler to use. Normally, this will actually be the thread’s parent ThreadGroup, whose handleException() method by default will print the stack trace.

However, we can actually override this process for an individual thread, for a ThreadGroup, or for all threads, as follows:

public class MyApplication extends Application {
private static Thread.UncaughtExceptionHandler mDefaultUncaughtExceptionHandler;

private static Thread.UncaughtExceptionHandler mCaughtExceptionHandler = new Thread.UncaughtExceptionHandler() {
@Override
public void uncaughtException(Thread thread, Throwable ex) {
// Custom logic goes here

mDefaultUncaughtExceptionHandler.uncaughtException(thread, ex);
//Here you can make api call to your server
}
};

@Override
public void onCreate() {
super.onCreate();

// Cache a reference to default uncaught exception handler
mDefaultUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
// Third, set custom UncaughtExceptionHandler
Thread.setDefaultUncaughtExceptionHandler(mCaughtExceptionHandler);
}
}

We can discuss so many things here like below. We all deal these things in our daily developer life. Hence i am not going to write these things here.

  1. What would be the DB Schema
  2. How you will you fetch Record based on Package identifier
  3. How about System Availability (What if system goes down)
  4. What about System Scalability
  5. What if Client does not have internet

--

--

No responses yet