Micro-services are the norm nowadays when building backend internet applications or business applications. Of course we would not want to build everything from scratch. What micro-service framework should we use then? If you work in Java, your choices basically boil down to either Dropwizard or Spring. If you work in Scala, you have more choices like Twitter’s Finagle, Play framework and others.
Between Dropwizard and Spring, I personally prefer Dropwizard. For Dropwizard seems simpler and has a more elegant design. Then, what will Dropwizard do for us as a developer? Let’s quickly run through a micro-service building virtual exercise.
Obviously our micro-service will be built on top of a HTTP server. So we will need an embedded HTTP server as a starting point. When it comes to embedded HTTP servers, we had quite some options in the past. You can read here for all the possible options. But, as of now, the clear winner is Jetty. So we will use Jetty as our embedded HTTP server.
Our micro-service will need to support RESTful API. There is even a standard for that. It is called JAX-RS, Java API for RESTful Web Services (JAX-RS). The best implementation in this case is Jersey.
With Jersey, you can use many pleasant markings to turn your POJOs (Plain Old Java Object) into web requests or web responses with easy. Take a peak at these markings:
Great, the Jersey does the heavy lifting of marshaling between web request/response protocols and our Java objects so that we can focus on our Java models instead of HTTP protocols. There are still issues: we would like to load our application configurations from likely a jason/yaml file, additionally we might want our request/response to contain jsons. We will need another library. Yes, that library would be Jackson.
Apart from the above, we might also needs supports like Metrics, Logging, JDBI and user input validator etc.
The good news is, Dropwizard provides all of the things above. I hope by now, you are convinced that using Dropwizard is a good choice for you when building your micro services. You can simply think of Dropwizard as a bundle of libraries that reflects the best engineering practices in the Java world.
To understand how a dropwizard project looks like and how they work, I found this was a very good starting point.
