Stormpath Java Support

The Stormpath Java SDK is now speedier and more extensible than ever. If you’re running a version lower than 1.0RC4.4, consider updating.

It’s no secret that an application needs fast access to its user data to keep those users happy. Whether it’s registration or authorizing access to a resource, slow speeds and good user experience don’t mix.

Which is why we recently revamped much of our core Java SDK to improve performance and extensibility. Here’s a rundown of what we did and how it impacted request times in a real project:

Pagination Bug Fix

First up, we discovered a bug preventing the SDK from iterating over collection resources correctly. As a refresher, collections in the Stormpath API are containers of other resources. For example, a Group contains Accounts, a Directory contains both Accounts and Groups, etc.

Prior to this release, requests to GET a collection that resulted in just one page of resources posed no problem, but multi-page results quickly broke down. A fix to the pagination logic took care of this.

An Elegant Datastore Implementation

We rewrote the core ‘DataStore’ implementation of the SDK – the very core of how all resources are processed in the SDK – from scratch. While not part of the original update plan, we found that an accumulation of improvements over the last two and half years resulted in too many one-off code chunks and an unnecessarily complex implementation. For a full look at the changes, take a look at this GitHub issue.

In addition to simply being a cleaner implementation, the new DataStore supports a ‘filter chain’ design approach that will allow us to plugin and cut out logic over time without creating the bloat. It also guarantees a consistent request/response flow for all interactions with our core REST API, meaning faster and more complete bug fixes in the future.

Fewer Round Trip Calls

Every iteration over a collection used to require two requests to Stormpath for the first page of results. Consider that extra call a relic of the past.

Performance via Gzip Compression

Gzip compression provides a 20% or more reduction in request times.

Improved Serialization

The Java SDK now funnels response bodies as a raw byte stream to Jackson, the JSON serializer Stormpath uses. Count this a small but real improvement of ~.5% reduction in request times.

Efficient Expanded Collection Handling

Consider the following real-world example: A Stormpath Application has access to 801 Accounts.
At a page size of 100, a request for this Application’s Accounts collection resource would require 9 requests. Before this release, GETting the Groups for each of these Accounts would initiate an additional request for each Account – resulting in 810 total requests. Not ideal.

With the new release, collections that have elements with expanded collections of their own (like the Group example above) are collectable without unnecessary requests to Stormpath.

Measuring Performance Improvement

Now for the good stuff! Let’s see how all these changes combined impact our example Application with 801 Accounts.

Before The Release:

Iterating over 801 accounts without any kind of expansion at all (two times):

Run 1: 7934 milliseconds (7.934 seconds)
Run 2: 7341 milliseconds (7.341 seconds)

Iterating over 801 accounts with Groups expanded (two times):

Run 1: 154806 milliseconds = 154.934 seconds = ~ 2 MINUTES
Run 2: 150999 milliseconds = 150.999 seconds = 1 MINUTE 50 SECONDS.

After The Release

Iterating over 801 accounts without any kind of expansion at all (two times):

Run 1: 4025 milliseconds (4.025 seconds)
Run 2: 3822 milliseconds (3.822 seconds)

That’s an almost 100% increase in performance.

Iterating over 801 accounts with Groups expanded (two times):

Run 1: 8817 milliseconds = 8.817 seconds
Run 2: 7349 milliseconds = 7.349 seconds

That’s an ~ 1800% increase in performance.

The best part? Strict separation between the SDK API and its implementation classes made it possible to push major upgrades with no API changes for our users. Also, tests help. Lots and lots of integration tests.

You can find the new SDK on Github and updated Java Docs here.