"He who rides a tiger can never get off or the tiger will devour him."

Software developers know the truth of this Chinese proverb. We ourselves have created an environment that forces us to cope with ever-increasing complexity. Twenty-five years as a software developer, manager and architect has taught me that every day has something to teach me. Here's what I'm learning now in the hope that it helps someone somewhere stay in the saddle and off the menu.

Sunday, April 18, 2010

Grails in the Cloud: The Democratization of SaaS

Software as a Service (SaaS) is an increasingly common delivery model for horizontal-market business applications such as CRM and HR, particularly at the enterprise scale. SaaS has compelling advantages for small-scale vertical-market applications as well. However, applications for these markets tend to be authored by a domain expert working alone or as part of a small start-up. The development complexity and run-time infrastructure costs associated with web application technologies are a significant barrier to these developers. That's why most software solutions for this market tend to be stand-alone applications written using productive, but fundamentally unscalable development platforms.

The emergent generation of web frameworks for dynamic languages can improve developer productivity by an order of magnitude compared to traditional web application development technologies. Cloud hosting of applications built on standards-based platforms provides an affordable path from development to launch to large-scale production. Taken together, these advances mean that a lone developer familiar with a given business domain can outproduce a typical corporate product development team and deliver (over the public network) service levels rivaling those of most corporate data centers. This creates new business opportunities to serve niche markets with SaaS applications that are clearly superior to current solutions, if current solutions exist at all.

Grails is an almost ideal development platform for this sort of SaaS application:
  • A single developer or small team needs to maintain a high degree of productivity to take advantage of market opportunities. IDE-focused platforms such as Visual Studio and script languages such as Perl and PHP offer high productivity in the initial phases of construction, but this wears away quickly as the highly-coupled, repetitive code these approaches tend to encourage becomes progressively more difficult to extend or maintain. Grails offers the combined productivity benefits of a dynamic language (Groovy), convention over configuration, and consistent integration of proven Java frameworks such as Spring and Hibernate. Grails helps the developer sustain these benefits over the entire application life-cycle by supporting design and coding practices such as loose-coupling, separation of concerns, and automated testing.
  • An SaaS application targeted to a large population of small organizations needs to have robust security and a multi-tenant architecture. The latter is particularly troublesome, since a "one database per tenant" approach creates significant administrative overhead, while a handcrafted "multiple tenants per database" approach brings extra complexity to the design and implementation. The Grails community offers solutions to these issues through plugins. For example, the Multi-Tenant Plugin integrates with the Spring Security plugin to provide these capabilities in a way that is almost transparent to the developer.
  • Applications of this sort are unlikely to attract the venture capital backing necessary to absorb the initial investment in production run-time infrastructure. Cloud hosting allows a start-up to incur infrastructure costs on a pay-as-you-go basis compatible with its revenue model. However, if the application becomes wildly successful, its architecture should support ready migration to a dedicated-host or even self-hosted model. Grails runs on the Java Enterprise platform, which is well-supported on both hosted cloud and commodity open-source infrastructure. Further, Grails plugins such as the Cloud Foundry Plugin provide seamless integration with the deployment infrastructure.
To demonstrate these capabilities, I put together a set of instructions to produce a Grails project suitable as a base for a low-budget SaaS application. These instructions are documented in the topic Creating a Secure, Multi-Tenant Web App with Grails on Riding the Tiger Wiki. I invite anyone who has an idea for an SaaS application that could benefit small businesses or non-profit organizations to try this out and see how Grails makes it possible.

10 comments:

  1. Dave,

    This is a great article on the power of Grails and Groovy. I suggest people check out the article Multi-Tenant Web App with Grails. The Cloud hosting creates a whole new opportunity for developers.

    ReplyDelete
  2. David,

    Your article on multi tenancy using grails is superb. Do you plan to do an updated version of this anytime soon?(spring security for e.g. instead of acegi and looks like tenantId problem might have been patched in plugin)

    Thanks
    Bala

    ReplyDelete
  3. As a matter of a fact, I'm working on it now. I'm upgrading our application to Grails 1.3.4 and Spring Security. Along the way, I'll find out whether the Multi-Tenant Plugin 1.0.0 works with Spring Security (as opposed to Acegi). I'll probably also look at the RelationalScope plugin as an alternative.

    ReplyDelete
  4. I had to wait for all of the versions of the plugins to catch up with each other before it was worthwhile to try to upgrade the application. Unfortunately, I found that even with the current versions (Grails 1.3.5, Spring Security Core plugin 1.0.1, Multi-Tenant plugin 1.0.0 and Multi-Tenant Spring Security Integration plugin 0.1), the same tenantId problem manifests itself. I applied the same patch to the new plugin, but I'm not happy about it. This means that the same show-stopper bug has existed in the Multi-Tenant plugin for almost a year -- even through a significant update. No one can have tested this plugin in multiTenant mode with an application that has at least one domain class that does not carry the @MultiTenant annotation.

    ReplyDelete
  5. Hi Dave,

    I also cannot get the multitenant plugin to work in multitenant mode as you mention(Grails 1.3.5, Spring Security Core plugin 1.0.1, Multi-Tenant plugin 1.0.0 and Multi-Tenant Spring Security Integration plugin 0.1)
    Did the patched version you built work. If so can you please share it(trbala at yahoo.com)

    Thanks
    Bala

    ReplyDelete
  6. Yes, the patched version works. It's the exact same fix that I documented in the section "Patch the Multi-Tenant Plugin" of the wiki article "Creating a Secure, Multi-Tenant Web App With Grails" referenced above, only applied to version 1.0.0 instead of 0.17. I'll update the wiki article -- probably next weekend.

    ReplyDelete
  7. For what it's worth, the tenantId issue may be fixed in multi-tenant-core 1.0.1.SNAPSHOT (https://github.com/multi-tenant/grails-multi-tenant-core/issues#issue/1). For this to do any good, the multi-tenant-spring-security plugin will have to pull in the new version.

    ReplyDelete
  8. Alright then. The just-released multi-tenant-spring-security plugin 0.2.1 pulls in multi-tenant-core 1.0.1 as a dependency. The tenantId issue is fixed in this release and you can (finally) just install the plugins and have it work.

    ReplyDelete
  9. Hi Dave,
    I was wondering if you have an upgrade version of the application, I really interesting in create a multi tenant app to deploy to aws using the current plugins , need to show to my team that grails is a great framework.

    ReplyDelete
  10. This article was a product of work I did for a project. I haven't updated that project to the current version of Grails yet.

    ReplyDelete