Tuesday, October 28, 2014

Getting request timeouts to work with spray-can

Request timeouts! This is such a basic feature of any RPC framework - some endpoints are just going to take a really long time compared to others, and you want to be able to wait for reallySlowRpc while still timing out quickly for shouldBeFastButSuperFlaky.

At AI2 we recently switched to using spray-can as our HTTP client, away from dispatch. Dispatch was great in that it let you get started quickly, and it's backed by the excellent-if-generically-named async HTTP client, but has the disadvantages of:
  • backing library is Java, not Scala
  • no Actor support (implied by the above)
  • very limited feature set out of the box
  • documentation is example-based, and sparse
Basically, dispatch is excellent if you need to get something running quickly, but very difficult to use for advanced applications.

spray-can, on the other hand, has great integration with spray-json (which we use for our RPC requests and responses), works well with actors, is pure Scala, and has moderately well-documented code.

The problem is that the actual APIs are often tricky to use. Very, very tricky to use - if the API hasn't been built to support a feature, it can take quite a lot of digging to unearth the right configuration parameter to give you what you need.

Which brings me back to request timeouts.