Apr 13

So, I wrote a decent backend in Java for WeatherMan last year. While the majority of my frontend code can be preserved, the backend is going to need a lot of work, for several reasons:

  • There was a nasty infinite loop somewhere in the code that I was unable to nail down the root cause of; some condition in the WeatherWire parser was causing the issue
  • I need to write a truly secure communications channel between phone and server; location information is stored and transmitted, and I want to make sure that is secure. Last year I was using a hashed and salted device token to authenticate with the server. However, the communications channel itself was unencrypted, and this required that the device send a token received from the APNS server, which is something I’d like to avoid doing.
  • The backend was never really set up as a daemon; start/stop was manual and there was no external control.

Because of the significant rewrites required, I’m probably going to end up breaking the whole thing down, reusing the code that works, but rethinking the architecture. This got me thinking–is Java really the best language to use for this?

Here is what the backend must do:

  • Keep a consistent connection via telnet to the WeatherWire server to pull down weather alerts
  • Parse the data coming into the telnet connection to decide what is an alert and what isn’t, and to break the alert down into an object that can be stored in the database
  • Keep records of all devices using the software and the locations they have requested to receive alerts for
  • Each time an alert comes in, find the location of that alert, match it to the device database, and send an APNS notification to each device that wants to receive alerts for that location
  • Connect to the NWS FTP servers to download data on-demand
  • Act as a cache for on-demand information (forecasts, radar images) to reduce loads on the NWS servers
  • Insert and retrieve all of this data from a MySQL database
  • Expose an HTTP server over an SSL/TLS connection that will take POST requests for data and return JSON datasets (there shouldn’t be any actual binary data required, as even the radar imagery will be in a KML format that is parsed on the device)

So basically, whatever language is used needs to have good networking libraries and good text/string processing capabilities, and needs to be fast enough to process the WeatherWire data in realtime (there can be quite a bit of it). Also, the backend must be able to run on a Linux server, which immediately counts out Objective-C/Cocoa and .NET for the backend. Here is the list of languages that I’m considering, and what I feel the pros and cons are. Any comments would be appreciated.

  • Java. Via the String class, Java has strong enough text-processing capability to meet my needs. Also, it has a large amount of open-source libraries available; I made extensive use of the Apache Commons libraries in the original version to implement telnet and FTP connections, and used the embeddable Jetty webserver to have a lightweight HTTP server to handle the JSON requests. Plus, while the JVM isn’t as fast as native code, it is generally going to be faster than an interpreter.
  • C/C++. C is a little lower-level than I’d like to use for this application; being able to take advantage of class libraries that will handle the finer points of network connections and string processing is something I would miss dearly. This option would definitely win on speed, however the learning curve and heightened security risks make me wary.
  • PHP. PHP would be the clear winner (at least in my experience) for the text processing and HTTP responses. However, the interpreted nature could cause slowdowns, and while I’ve seen a lot more non-Web platform PHP use recently, I’m not sure if the tools are all there (anybody ever seen a Telnet library written in PHP?). Plus, can it be easily daemonized?
  • Python. I have no experience with Python, but I do know it has a fairly extensive standard library and a lot of developer support. The interpreted nature and potential difficulty daemonizing are a couple of potential pitfalls.
  • Ruby. Another language with fairly extensive developer support that I do not have any experience with. Again with the interpreted nature and daemonization, though based on the Rails framework I could see some ease with the server portions of this.
  • Go. Google’s Go intrigues me as a language. It seems to me that it would offer a lot of the benefits of C/C++ without a lot of the pitfalls (namely direct memory access). The newness of it is a turn-off though–specifically, there is no native connector for MySQL.

If you have any thoughts or insights I’d love to hear them. I’m up for learning something new if it will meet my needs in a better way than Java currently is.

Tagged with:
preload preload preload