I just recently stumbled across this interesting presentation from Ben Christensen, a Software Engineer in Netflix. Netflix has developed an interesting approach to create a high performance and scalable system. This approach gives Java capability of Functional Programming, before Java 8 with Lambda support went public. They call it ReactiveJava, or RxJava for short. RxJava is a library for creating event-based application, using technique called Observable pattern. More detailed informations are available on their site or their github repo.

I just started learning this, and all I can say is RxJava is a very interesting library. It will take some time to learn (or adopt), but resources below I found very helpful.

  1. Ben Chistensen’s video presentation at GOTO Conferences.
  2. Russel Elledge’s Course about Reactive Programming using Java 8.
  3. Leo Campbell’s Book: Introduction to Rx.

Weird Bug in Chrome

I would like to tell a story about the newest thing I found related web development. We are currently building an integrated system for promotions and coupons related. The system consists of an Android client, a RESTFul API Server module, and a Content Management System (CMS) module. We use Jboss Wildfly 8 as our Application server, running on top the Java 8. We love Java 8’s functional capability, but I will save the details on the other post.

So the problem started after we are doing deployment into our production environment. Some users send bug reports about the problem in login process. After doing some thorough investigation, we found that we missed redirect tag used in Shiro authentication. Adding those missing tags,compiled new binary and done! Our modules are updated in production server.

Our users then perform their usual activities. The login problem apparently has been addressed with our latest fix, so we continued the development process. After a couple of minutes, a new bug report came in. And the bug is very weird. Some users using Google Chrome browser, experiencing some oddities interacting with our CMS. Several users report that they need to click submit button twice before they can login. The problem did not stop there, they said that our system kicked them out after just clicking some menu.

Our first approach is examining our server’s log, to find root cause of this problem. After doing some testing, we found that the server was performing just fine. Our authentication system responds in the correct manner. Based on our experiences, this could means one thing, the problem is on the client’s (browser) side. We then prepared several browser in different conditions, trying to reproduce the weird bug. After doing some tests, we find that only Google Chrome browser has this problem. Any other browser does not have this problem, which is weird, since Chrome has a good reputation related with web technology standards.

Since we have not experienced this problem before, we immediately went back into our first hunch, that the problem is mostly located in the server side. We did quick comparison our current production environment configuration with our development and staging environment, to find differences that could lead to this problem. We found that the only differences between our environment is that our production use nginx’s virtual host heavily. Again, this kind of approach deserves another blog post. So, we splitted our development team into two, the one with backend specialties will investigate our current nginx configuration, whilst our frontend gurus will perform debugging in the browser side.

This scenario was effective, our backend team can easily confirm that our nginx is not having any faulty configuration that cause that problem. So, we can put our focus into frontend debugging. As usual, some queries sent to Google leads us into several StackOverflows discussions, but nothing giving us clear answer about this problem. We fired up the firebug toolbar, and examined what interactions actually happens.

I have to admit, we approached this problem in not efficient way, since by using Firebug, we easily figured out why our user has to click Submit button twice. We found that Chrome is trying to load a favicon file, which does not exist in our newest build. We immediately put our favicon into assets folder and put appropriate code to load it. One engineer is curious and query google with favicon and login keyword leads into interesting StackOverflow discussion at http://stackoverflow.com/questions/8880592/chrome-and-jsessionid. We then went to that discussion in details and found an answer. Finally, somebody had a problem like us in the past and solved it!.

Apparently, Chrome and other WebKit-based browser use different approach in handling pages with redirect. Chrome creates two separate JSESSIONID cookies, first time is when our login form appeared, and one after successful login. Since the content of JSESSIONID has been updated, any further request marked as invalid and system forces user to login again. Following the lead, then we examined our code and put our favicon into proper place. We build new version, deployed them and the problem was gone.

This problem was hard and weird. We spent hours in confusion, but in the end of the day, we went home with new knowledge. This information will be very useful in the future, to help us build a better application.

Learning Clojure

One of many remarks that I took from Computer Science world in 2013 is the rise of Functional Programming. After years of doubt about its performance comparing the other Programming Paradigm, Functional Programming (FP) finally took its place when most of big players choose to implement FP language in order to handle big data traffic and doing real-time data processing. Scala, has enjoyed the hall of fame in last 2 (two) years, by helping Twitter building their services. Twitter makes some crucial libraries in Scala, and it has been proven that Scala can handle big data better than other programming language, i.e Java or Ruby.

I myself feel very thankful for my almamater for teaching us FP in older days. We learnt Haskell in our Foundation of Programming classes, gave us headaches, because it worked very differently from Java, the first programming language we learnt. One thing that I remembered that FP is helping me to understand the principal of recursion. The recursion code in FP is way more clearer and easier to understand than the Java companion code. But again, we left Haskell in the dust and use Java for the nex assignments until now.

After reading some successful stories about FP implementation, I decided to jump into the same bandwagon. I chose to implement our project at work to get a view about developing Services using FP. To give a brief overview, our current Service built around Java with some Ruby and Python here and there. We use RESTFul to communicate within our modules, and it uses PosgreSQL and some NoSQL databases to store the different kind of data. Based on these circumstances, I think this Project will be very fun to develop using FP.

In 2013, some new FP language finally take the spotlight, giving us another option beside Scala. Don’t get me wrong, I think Scala is great, but the language is very complex. I am looking for more simple approach for FP language, but still can run in Java Virtual Machine (JVM) like Scala. There are some alternatives like Clojure, Groovy and the future, Java 8. The main reason to use JVM-based FP language because it let us to use Java’s 3rd-party library in the FP way. We can reuse the libraries and modules, so we can keep the destruction minimal.

Between Clojure and Groovy, I finally pick Clojure as my next adventure. Clojure has many advantages, as describe in here [1]. Clojure is the most interesting language between the three. It use LISP dialect, where it is so uncommon nowadays.

The next step is to find the good resource to learn Clojure, after doing some Google Search, I found 2 (two) books. The first book is Clojure Programming by Chas Emerick, Brian Carper and Christophe Grand. By reading this book, you will get familiar with Clojure syntax and its capabilities.

The other book is The Joy of Clojure by Michael Fogus and Chris Houser. This book is not for newbie in Clojure. It contains some advanced technique in Clojure that not really easy to understand by beginner programmer.

The other resource for learning Clojure that I’ve found useful is Leiningen. Leiningen is the maven for Clojure, but with much more capabilities. Other than managing your project dependencies, such as libraries and modules, Leiningen also provide a REPL for Clojure. This is the biggest winning feature for me. By issuing lein repl command, I got a full Clojure environment and I can start coding right away. This is the most missing feature from Java IMHO.

At then moment, I am still familiarizing myself with the syntax and patterns, and I hope in the short time I can start my experiment and share the result.

– Fin

  1. http://www.quora.com/Clojure/Why-would-someone-learn-Clojure “Clojure: Why would someone learn Clojure”  ↩