Upgrade to Pro — share decks privately, control downloads, hide ads and more …

The Constellation Architecture — All the Little...

The Constellation Architecture — All the Little Apps

The Constellation Architecture — All the Little Apps
Shane Becker
My team and I were brought into The Company™ to help them take their One Big Monolithic Rails App™ and turn it into a a handful of smaller Rails apps that all work together… mumble mumble SOA mumble mumble.
When I started looking at it, I realized that 4 or 5 apps was only just scratching the surface. Instead of 5 apps, 1 for each product with a multi-tenant database, we've decided on 1 app per client, with NO multi-tenant database.
We have a few internal admin apps, then a whole slew of client apps. Each client has an admin app, a deployer app (to deploy the client admin), and n apps per client that are end-user facing.
- company admin apps:
- client admin deployer:
- client admin:
- end user site
- end user site
- end user site
- …
It's the classic Rails app story. Built in 2007 and piled onto for 6 years. Lotsa of version bumps and upgrades, but never any serious refactor. It's grown and grown. Clients have grown and grown. The technical requirements and cost of operating has grown and grown.
By doing this re-architecting we've reduced:
- the technical complexity of each app (each piece of the previous one big app)
- the resource requirements of each app
- the cost of operation
…considerably.
Oh, and we're doing all PULL (no push) and HTML with microformats as "API output" (no JSON).
Those three things (lots of little apps, pull, html) are changing everything for us.

Shane Becker

April 29, 2013
Tweet

More Decks by Shane Becker

Other Decks in Programming

Transcript

  1. There Are Exactly Two Ways to Put the Toilet Paper

    on the Roll: Over the Front & The Wrong Way There Are Exactly Two Ways to Put the Toilet Paper on the Roll: Over the Front & The Wrong Way
  2. The Constellation Architecture All the Little Apps My real talk

    hashtag is called: The Constellation Architecture — All the Little Apps
  3. Who here knows of me? Who here knows OF me?

    Hi. It's nice to meet you. My slave name is:
  4. El Pueblo de Nuestra Señora la Reina de los Angeles

    del Río de Porciúncula Los Angeles, CA LA. Which is a BIG fucking city. With a big fucking name. In fact, it’s as big as 8 other U.S. cities combined:
  5. St. Louis, Milwaukee, Cleveland, Minneapolis, San Francisco, Boston, Pittsburgh and

    Manhattan. St. Louis, Milwaukee, Cleveland, Minneapolis, San Francisco, Boston, Pittsburgh and Manhattan. I live in the Minneapolis of LA. So, please keep that in mind next time you ask me to pick you up from the airport. Photo credit: https://www.facebook.com/photo.php?fbid=10151078446867664
  6. Farmhouse Conf Farmhouse Conf. You should come to it. If

    you live in the LA area, definitely get a ticket and come to it. If you don't live in LA, butyou're feeling wild and adventurous, buy a plane ticket and come down for a couple days. You won't regret it.
  7. Aaron Patterson, Andy Baio, Brian (Crimethinc), Caroline Woolard, Eli Duke,

    Eric Gradman, Evan Phoenix, Greg Bennick, Jenny Ryan, Kate Darling, Leah Silber, Maggie Mayhem, Marc Horowitz, Megan Dean, Meghann Millard, Michael Lopp (@rands), Micki Krimmel, Mitch Artman, Nova Han, Peter Young, Sarah Mei, Sean Bonner, Shepard Fairey, Simone Syed, Suzan Bond, Tara Brown, Tj Nelson Jr, Zoetica Ebb All these awesome people. Some of which are here at Rails Conf this weekend. The next one is:
  8. Jacob Appelbaum @ioerror Jacob Appelbaum @ioerror COINTELPRO — Past, Present

    and Our Shared Future Who you nerds might know better as "@ioerror".
  9. Adam Lisagor @lonelysandwich Adam Lisagor @lonelysandwich The Children Are Our

    Future The maker of all those awesome Sandwich Videos for: Square, Jawbone, Airbnb, and many more.
  10. Erika Brooks Adickman @ThisErikaLife * Erika Brooks Adickman @ThisErikaLife A

    Neurotic Gal Attempts A Fearless Look Into The Future.
  11. Zach Klein @zachklein * Zach Klein @zachklein We Will Build

    Offline in the Future Co-founder and designer of Vimeo, Svpply and most currently DIY.org.
  12. Jessica Lord @jllord * Jessica Lord @jllord Future Commonwealth Who

    designs gorgeous maps of cities and their imagined futures.
  13. Ron Evans @deadprogram * Ron Evans @deadprogram Future Current: The

    Robot (R)Evolution You all know Ron Evans. He'll have his robots out.
  14. Colleen Jordan @colleeniebikini * Colleen Jordan @colleeniebikini What We Will

    Make in the Future Who makes 3D printed plant holder jewelry.
  15. willowbl00 @willowbl00 * willowbl00 @willowbl00 Replacing Uppercase “F” Fucked with

    Uppercase “F” Future : Active Participation in Response Talking about hackers, humanitarians, makerspaces, and our role as responsible citizens building The Future™.
  16. Srsly. Please come to it. I'm incredibly proud of it.

    It's, by far, the best thing I've ever made. And the final one is:
  17. New Product We are building a new product Which this

    talk is extracted from: And, of course, Photo credit: http://en.wikipedia.org/wiki/Orion_(constellation)
  18. My First Rails App™ The developer who started it (our

    now CTO) had never written any Ruby or Rails but wanted to try it out.
  19. Learning by Doing He was making it up and figuring

    it out as he went. There's nothing wrong with that.
  20. 6 Years Later The codebase has been piled onto for

    6 years now. And it's just like you would expect.
  21. He / We Learned a Lot During that time, he

    has improved as developer in general. And in the ways of Ruby and Rails idioms. Ruby, Rails and the ecosystem around the two have grown and improved in that time too.
  22. Works in Production Of course, let me be fair. Things

    might be less than optimal in the codebase itself, but that hasn't stopped customers from using it and the company to make millions of dollars from the product.
  23. The L.A. Team I wrote a blog post in September

    2012 offering up me and 4 others as a cross functional product team for hire. 2 Ruby / Javascript developers. 1 Designer. 1 Front end developer. And me as Mr Manager.
  24. “Hire Us” We were hired 33 days later. G5 needed

    another team to expand their capacity and build a new product.
  25. Primary Objective When we were brought in, we kept hearing

    the story of big and cumbersome the product and codebase were.
  26. All or Nothing For a customer to try out The

    Product, they had to use and pay for it in its entirety. They couldn't use just this small piece over here, then upgrade to additional pieces with time.
  27. Many Products in One The Company had identified that there

    were really 4 or 5 products inside of the big one.
  28. Sold Separately And if the technical changes could be made,

    then they could sell them as separates pieces.
  29. À La Carte The Customer could choose the pieces that

    make sense for her business, then add pieces in the future as her needs changed.
  30. Tribal Knowledge Because of the complexity, certain bugs and features

    always went to certain people who knew those parts of the codebase best. Billing, I'm looking at you.
  31. Common Trajectory It's a path that a lot of quick

    and dirty Rails apps take. They continue to grow until they're just too big to manage.
  32. Unbundling Along with the story of "it's too big!", I

    kept hearing this desire to "unbundle" the big app into a handful of little apps.
  33. SERVICES ALL THE THINGS Service Oriented Architecture seems to come

    and go in fashion as The Magic Wand solution to all your problems.
  34. No One Answer There are lots of problems and lots

    of solutions. There is no one solution to rule them all( and in darkness bind them).
  35. Ask Around Ask yourself. Or your neighbors in this room.

    Or people out in the hallway. Or your boss. Or favorite tech blogger. What they think SOA is? You'll get different answers.
  36. E.g., SOA means Enterprise™. SOA means XML. SOA means SOAP.

    SOA means Java. SOA means JSON. SOA means Node.js. SOA means messaging queues. SOA means PUSH. SOA means async.
  37. That's OK I don't particularly care what SOA is or

    isn't. Or whether or not we're doing it The Right Way™.
  38. Different Story I knew of all of those stories about

    what it meant to use services. But I wanted to try something different. A few different things actually.
  39. Remember the tl;dr? At the beginning of my talk, I

    mentioned the four take away points.
  40. Multi-Tenant Database A multi-tenant database is one where all of

    your users' data is intermingled in the same place.
  41. Rails 101 This is basic stuff. Rails 15 minute screencast

    kinda stuff. Nothing earth shattering.
  42. Security By having all of your users' data in the

    same place, if one person is able to compromise the database and gain access to it, then she gains access to everyone's data.
  43. Privacy If you ship a bug that show the wrong

    data to a user, you're potentially showing someone else's data to someone else. Potentially, private data.
  44. Corruption If one user intentionally or unintentionally corrupts the database

    or saves corrupted data into the database, all users are potentially affected. Not just the one user who screwed up.
  45. Uptime Again, if one user manages to intentionally or unintentionally

    take down the database, it's taken down for everyone. Until you run your backups or fix the problem.
  46. Single Tenant Database A single tenant database is one where

    all of the data is owned by one user.
  47. Single Tenant Database A single tenant database is one where

    all of the data is owned by one user.
  48. Security That means, if the database is compromised, only one

    user is at risk. One user is worse than zero user, But better than all users.
  49. Privacy It's impossible to show the wrong data to a

    user with a single tenant data, because there is no wrong data. Nothing belongs to someone else. It all belongs to the only user.
  50. Uptime Same is true for Uptime. Only one user is

    taken offline if the database goes down.
  51. Unless… It's only a crazy idea if your site has

    1 big Rails app and many little databases.
  52. Trade Offs Again, all design decisions come with trade offs.

    Running little apps with little databases means some things are gonna be different for us.
  53. Deployment Deployment being an obvious trade-off. Let's say we have

    1000 users. We update the codebase and need to deploy to all the users.
  54. Scheduling We can schedule the deploys and `git push` down

    a list of apps until we hit all 1000 of them.
  55. Batching Similar to scheduling, we can grab a group of

    apps deploy them all at once. Grab another batch, rinse, repeat. Both seem like they have a lot of overhead and complexity. Something I didn't want to deal with. And they seemed fragile too.
  56. “Should I Update and Deploy?” Each app periodically asks an

    admin app if it should update. If "yes", then it goes off to GitHub, `pulls master`, `bundles`, `db:migrates` then finally re-launches the site.
  57. Buddy System Because we're using Heroku for this and Heroku

    apps can't re-deploy themselves, we actually use a buddy system. Each app has a sibling that deploys each other.
  58. A <–> B App A listens for instructions to update/deploy

    app B. App B listens for instructions to update/deploy app A.
  59. Limited Concerns We want each of our types of apps

    to be simple technically and conceptually. The old "only do one thing" principle.
  60. G5 Hub In our system, the first thing we need

    to do is create clients. That's a pretty simple thing conceptually. We call this the "G5 Hub" because only G5 admins login to it to create new clients.
  61. Client Hub The apps that users access directly to do

    their admin stuff, we call that app a Client Hub. Its buddy is called a Client Hub Deployer.
  62. Bubble Up In between the G5 Hub and all of

    the Client Hubs, we have a handful of apps that handle the automated creation, initial deployment and bootstrapping new apps.
  63. One App Per Client Remember, we end up with 1

    Client Hub for every client.
  64. Two Apps Per Client But because of the buddy system,

    that's actually two apps per client: Client Hub and Client Hub Deployer.
  65. Inter-app Communication To explain how each app talks to other

    app, we have to move on to the other two unconventional ideas in our Constellation Architecture.
  66. “Polling” "Polling". And you would be right. Technically, what I'm

    talking about when I say "Pull" (with a U) is actually "Poll" (with an O). But it just feels wrong.
  67. Push & Pull Push and Pull are antonyms and that

    mental symmetry feels right to me.
  68. The Hottness These days Push is all the rage. Kids

    are like PUSH ALL OF THE THINGS.
  69. Kinda Makes Sense It seems like a good idea. "Here.

    I have this thing. I am giving it to you."
  70. XML

  71. PNG

  72. *

  73. Permalink The blog app creates the new post page. In

    Rails parlance, that'd be posts#show.
  74. No Push That's it. Just adding a page to her

    site. Super simple. Super easy. Super inexpensive.
  75. Imagine Imagine if every time a blogger wrote a new

    post, her site had to push a message to all of the readers and subscribers of her site.
  76. Popular Site Now imagine if a very popular blog with

    millions of readers had to do that. Now multiply that by several posts per day.
  77. Overworked Server Her server would fall down under the weight

    of that load OR it would cost her an arm and leg to keep it up and running.
  78. Final Piece The final piece of the puzzle, or at

    least of **our** puzzle, is how do wrap up the data that we're reading between apps.
  79. JSON Duh, right. Everyone uses JSON for all of the

    things. That's just what you do.
  80. XML "We used to use XML for all of the

    things, but that's sooo last version of Rails ago." Or... "XML? Ugh. That's for the enterprise."
  81. Trends It seems like every few to several years, there's

    the new One Right Way for APIs to talk at each other.
  82. Why Not? So, why not use HTML as the media

    type for our inter-app communication?
  83. Integers / Floats The one that I don't have a

    great answer for is integers and floats. But we can just duck type smash our way through that one.
  84. White-Space Ambiguity When I asked around on Twitter about how

    people felt about HTML as API output, the most legit answer I heard is that HTML has ambiguous rules on how to parse whitespace. That's a very fair point. Something to consider and act on accordingly.
  85. Formats Another concern, I often hear from people is that

    "how will I know what to expect from an HTML API?" Or "what format will the data be in the HTML output?"
  86. XML Formats? There are a bajillion XML formats for all

    of the things. But most noticeably, there's
  87. JSON Formats? Every API is a unique and beautiful snowflake

    rolling its own particular format using the JSON media type.
  88. Activity Streams Activity Streams has an XML representation (built on

    Atom) and JSON representation. Effectively, no one is doing anything with this. Which is a bummer. I really wanted Activity Streams to gain traction.
  89. RSS JSON rssjs.org Dave Winer is asking the question /

    loosely proposing a JSON representation of RSS. Which I think is a total shit show. But besides that, literally no one is using it.
  90. HTML Formats? HTML has a rich set of formats for

    higher level data. The most widely used and my favorite is called
  91. h-entry h-entry is the one that we care about most

    in our architecture of little apps.
  92. Websites At the end of the day, our whole big

    Constellation Architecture is just websites publishing HTML that humans and other websites read.
  93. Web Scale™ If it works for the web as a

    whole, it'll work for your web app.
  94. Thank You I know your time and attention is more

    precious than any other commodity. I appreciate it greatly that you gave me a few minutes of it.