Metaprogramming + DBaaS = Customization

By Markus Klems

From my experience in the CRM industry I can tell that there is a huge demand for customizable applications in the market. What does customizable mean? It simply means that the customer can tailor the application according to her wishes. Imho with traditional programming languages and database systems, like Java and MySQL, this is a task that will keep you busy for months or even years. And in the end you will probably fail.

The problem is that Java (just like C++) is a general-purpose programming language. Perhaps I am just a bad Java programmer but this is how I would program a customizable application in Java: create a wrapper class with Maps and Sets that can be dynamically filled with Strings, Integers, etc. at run-time. A Product class could (in addition to typical fields like productName and productNumber) have a map customizedFields<String,Object> that a user would fill with random fields when running the application. A user could add a field “color” or “size” through the customizedFields map. She could access and manipulate the field value by accessing and manipulating the object that she gets with the map’s key (“color” or “size”).

Of course, you could do something similar also with XML, JSON or whatsoever. And: you will have to change the database, too. You must add or remove tables in a relational database, etc. Now, I think there is a better way to do this…

DBaaS

Database as a Service is one of the more interesting *aaS derivates. With SimpleDB Amazon offers database functionality as a Web Service. Why would this make sense? Amazon argues that

Traditionally, this type of functionality has been accomplished with a clustered relational database that requires a sizable upfront investment, brings more complexity than is typically needed, and often requires a DBA to maintain and administer. [Source]

If scalability is king, why not install MySQL on EC2? You could use a redundant, self-healing and self-scaling framework like Scalr. I am sure that we will see more and more frameworks like Scalr appearing on the scene. But there is another interesting implication of DBaaS, as we will see later.

Metaprogramming

Metaprogramming means that “programs write programs”. This can either be done at run-time or at compile-time. Pragmatic Dave says:

Metaprogramming lets you program more expressively. This makes your code easier to write and easier to maintain and extend.

There are languages that are better suited for metaprogramming (Ruby, Python) than others (C, Java). Interestingly the Google App Engine currently is only available for Python. This is a severe restriction but imho it also shows some exciting possibilities. With the App Engine datastore API (the Google approach to DBaaS) developers can stay in their object-oriented Python world. No JDBC, no Hibernate.

Combine metaprogramming with DBaaS

Now, what do we get if we combine those two? With DBaaS I don’t have to care about my database, as I access it like a Web Service. With metaprogramming I can create classes, add methods to them or remove them at run-time.

VoilĂ , I can create classes at run-time and persist them dynamically with my flexible DBaaS.

Leave a Reply