Splitting up a Rails App / Multi-Application Architecture

Hi everyone! First time posting here – thanks in advance for your input!

I’ve just started working on a project consisting of (1) a web app (well-built, well-tested, somewhat complex) that’s been smushed together with (2) a converted Wordpress website (mostly-static, somewhat fragile, poorly-tested). The code lives in one Rails application and is hosted on one Heroku instance although the web app exists on a separate subdomain from the website.

I’m planning to recommend that the website be split into a separate codebase and hosted separately, but I want to make sure I’m considering all of the pieces before I dive in.

My reasoning:

  • There’s very little shared code between the app and the website; some assets (images, mostly) are shared.

  • The website is primarily static pages right now, but there are a few parts that are database-backed; none of that data currently overlaps, but the website shares a database w/ the app.

  • Separating the code will allow us to confidently make more frequent, incremental changes to the website without breaking unrelated portions of the app, and vice-versa.

  • Relatedly, the code backing the website needs a decent amount of refactoring to be more maintainable.

Some other considerations:

  • The website has enough dynamic content that it would need to become a separate Rails app; something like Jekyll or Middleman wouldn’t work (unfortunately).

  • There are longer-term (6 months+) plans for a more robust content-management solution for the website. Eventually, some of that content may want to be displayed within the existing app. (I’d expect to use or create an API for this, depending on the CMS solution we choose.)

  • We may eventually want to auth against the existing app for access to the website CMS. (Also longer-term.)

  • Analytics. I don’t have as much experience here. We’re currently using Mixpanel, and data from website events (page and video views, etc.) is combined with data from web app events (registrations, certain CRUD actions, etc.). I would expect there to be an initial challenge of splitting that data up. We’d also want to continue tracking referrals from the website to the app and vice-versa.

  • There are additional time and $ costs involved with maintaining a second hosting infrastructure. (I’m not super concerned about this.)

I’d love to hear any comments or other points I might consider. Thanks!

Have you considered doing a static site but managing the content with something like https://www.contentful.com? Not affiliated, but it seems like an interesting solution to your problem.

Do the website and app share anything other than assets (assets can be packaged in an asset gem and re-used)? Would it cause you to duplicate any code? Do the website and app need to access the same data at all even in the slightest?

You mentioned separating the code will allow more confident changes to each part. The fact that changes to the app break the website or vice versa, leads me to believe they are more intertwined than I’m reading.

What are the dynamics bits of the website? Is rails really necessary to pull this off or can you use an off-the-shelf CMS? I’d be way more excited about splitting it out if what you split out saves you a maintenance burden.

@derekprior These are all great points, thanks.

I don’t believe there would be much code duplication, although I’m still working my way through the existing codebase. The two parts may indeed be more coupled than I realize.

There’s no current need for any of the data to be shared. We may eventually want to display or link to some of the website content from within the app - likely as “recommended content” based on an action a user takes in the app. The app wouldn’t be creating or updating website data/content, though.

I’m debating whether an off-the-shelf CMS may be a better solution. The dynamic parts of the website consist primarily of a voting functionality for visitors to choose contest winners and leave feedback for the entries. Our designer also designs and builds each page on the website individually (i.e., there’s not a single template to just drop content into); he has some concerns about starting over with another CMS’s templating system, having just switched from Wordpress. OTOH, decreasing our maintenance overhead would definitely be nice.

Coincidentally, I happened to find your blog post while looking into bundling static assets into a gem, and found it particularly helpful. I’ll link it here as a reference for others: http://prioritized.net/blog/gemify-assets-for-rails/

@Jurre I wasn’t familiar with Contentful, but I’ll check it out. Thanks!