< Return to Video

RailsConf 2014 - Rails as an SOA Client by Pete Hodgson

  • 0:17 - 0:20
    PETE HODGSON: OK. So, thanks for coming.
  • 0:20 - 0:26
    Today I'm talking about Rails as an SOA client.
  • 0:26 - 0:30
    So, in the beginning, there was a Rails application.
  • 0:30 - 0:33
    And in the beginning, most of these Rails
    applications
  • 0:33 - 0:34
    were pretty straight-forward.
  • 0:34 - 0:37
    Pretty simple things. They were normally
  • 0:37 - 0:39
    just talking to a single database.
  • 0:39 - 0:43
    And this is how most of our Rails applications
    start.
  • 0:43 - 0:46
    They're green fields, and we're talking to
  • 0:46 - 0:48
    a single database.
  • 0:48 - 0:51
    Quite often, we, or pretty soon, particularly
    now days,
  • 0:51 - 0:55
    we start talking to services. These might
    be external
  • 0:55 - 0:59
    services like Twillo or Twitter, or they might
    be
  • 0:59 - 1:01
    internal services that we're using as part
    of doing
  • 1:01 - 1:05
    our job in a, in a more enterprise-y situation.
  • 1:05 - 1:10
    And as time has gone on, we've noticed, or
  • 1:10 - 1:12
    I've noticed, that our Rails applications
    are depending more
  • 1:12 - 1:15
    and more on services. So, I think there's
    kind
  • 1:15 - 1:18
    of two big forces in play here. Force number
  • 1:18 - 1:22
    one is, as time has grown and as Rails
  • 1:22 - 1:26
    has matured and our community's matured, our
    Rails applications
  • 1:26 - 1:27
    have been kind of growing into these big monoliths,
  • 1:27 - 1:31
    mono Rails, these big, bloated applications,
    and now there's
  • 1:31 - 1:34
    this kind of movement, quite a widespread
    movement, meant
  • 1:34 - 1:38
    to break up our large, monolithic Rails apps
    into,
  • 1:38 - 1:40
    into services and, obviously, something needs
    to talk to
  • 1:40 - 1:42
    those services. And normally that is a Rails
    app
  • 1:42 - 1:44
    fronting those services.
  • 1:44 - 1:48
    The second big force is, Rails applications,
    which I
  • 1:48 - 1:50
    think started off mainly being used by start
    ups,
  • 1:50 - 1:53
    have moved more and more into enterprise-y
    places where
  • 1:53 - 1:57
    there are a lot, lot, lot of services. And
  • 1:57 - 2:00
    in these enterprise contexts, Rails apps are
    normally talking
  • 2:00 - 2:02
    to a lot of services to get their job
  • 2:02 - 2:02
    done.
  • 2:02 - 2:06
    And this is, even goes to the extreme where
  • 2:06 - 2:07
    we have Rails app that don't actually have
    any
  • 2:07 - 2:09
    local data storage at all, are not doing any
  • 2:09 - 2:13
    kind of persistence. All they're doing is,
    is interacting
  • 2:13 - 2:15
    with services to do all of their work.
  • 2:15 - 2:19
    So, I, I built an application like this fairly
  • 2:19 - 2:25
    recently, and I'm gonna talk to you guys about
  • 2:25 - 2:27
    what we built, some of the techniques we used
  • 2:27 - 2:30
    to be successful in building these kind of
    services
  • 2:30 - 2:35
    only application. Yup. So that's, that's gonna
    be the
  • 2:35 - 2:36
    talk today.
  • 2:36 - 2:38
    My name is Pete. I work for this consulting
  • 2:38 - 2:42
    company called ThoughtWorks. So, we work with
    clients to
  • 2:42 - 2:45
    help them build software and get better at
    building
  • 2:45 - 2:49
    software. I've been with ThoughtWorks for
    about four years.
  • 2:49 - 2:50
    As you can tell from my accent, I'm in
  • 2:50 - 2:53
    the San Francisco office.
  • 2:53 - 2:55
    I really am in the San Francisco office. And
  • 2:55 - 2:58
    I, I, in my time in ThoughtWorks, I've done
  • 2:58 - 3:00
    a lot of different things. I've done a fair
  • 3:00 - 3:02
    amount of Ruby and Rails, but I've also done
  • 3:02 - 3:05
    some Scala, some JavaScript, some, some iOS.
    And I've
  • 3:05 - 3:08
    also worked in a lot of different contexts,
    organizations.
  • 3:08 - 3:11
    So I've worked in really small start ups all
  • 3:11 - 3:13
    the way through to huge, lumbering banks.
  • 3:13 - 3:16
    And, one of the things that I love about
  • 3:16 - 3:17
    ThoughtWorks is I get to move in all these
  • 3:17 - 3:19
    different places. And one of the things that
    I
  • 3:19 - 3:23
    think ThoughtWorks brings to its clients is
    ideas from
  • 3:23 - 3:27
    one place applied in a different place. So,
    what
  • 3:27 - 3:28
    we find ourselves doing a lot is taking ideas
  • 3:28 - 3:31
    from the Rails community and introducing them
    to the
  • 3:31 - 3:34
    Scala community. Or taking ideas from mobile
    applications and
  • 3:34 - 3:37
    introducing them to our client-side JavaScript
    applications.
  • 3:37 - 3:40
    And, indeed, taking ideas from start ups and
    taking
  • 3:40 - 3:43
    them to the enterprise. And so, shockingly
    enough, vice
  • 3:43 - 3:45
    versa. So, that's part of what I'm gonna be
  • 3:45 - 3:47
    talking about today is, there's this subtext
    of kind
  • 3:47 - 3:49
    of taking ideas from other communities that
    are successful
  • 3:49 - 3:54
    and bringing them into the Rails community.
  • 3:54 - 3:55
    And so this is gonna be a kind of
  • 3:55 - 3:57
    a talk in two parts. The first part I'm
  • 3:57 - 3:59
    gonna talk about some kind of more hand wave-y,
  • 3:59 - 4:03
    how do we live in this ecosystem environment.
    And
  • 4:03 - 4:05
    some tools and techniques that can help with
    that,
  • 4:05 - 4:07
    particularly in the context of Rails. And
    then I'm
  • 4:07 - 4:10
    gonna dive into some more kind of nitty gritty
  • 4:10 - 4:11
    kind of, how do we actually build these things
  • 4:11 - 4:12
    into our Rails applications?
  • 4:12 - 4:18
    So, first off. Co-dependence versus independence.
    So, as I
  • 4:18 - 4:21
    said, I worked for a client. We were building
  • 4:21 - 4:23
    a large, we were building, actually, a pretty
    small
  • 4:23 - 4:26
    Rails application in front of a very large
    set
  • 4:26 - 4:30
    of services. We were building an online store
    for,
  • 4:30 - 4:33
    for a large book retailer. They were going
    to
  • 4:33 - 4:34
    a new market, and they didn't want to have
  • 4:34 - 4:38
    to keep working in Java. So they were taking
  • 4:38 - 4:41
    this as an opportunity to build a green-filled
    Rails
  • 4:41 - 4:44
    app for a new market, which was still gonna
  • 4:44 - 4:46
    be using all of their existing services, which
    were
  • 4:46 - 4:51
    implemented in a variety of languages.
  • 4:51 - 4:52
    So this is what the home page of this
  • 4:52 - 4:55
    application kind of looked like. There was
    this kind
  • 4:55 - 4:58
    of list of all the products and prices and
  • 4:58 - 5:00
    descriptions and all that kind of stuff. And
    then
  • 5:00 - 5:01
    across the top we had these kind of deals
  • 5:01 - 5:04
    of the day.
  • 5:04 - 5:07
    And the way that this worked was, was interesting
  • 5:07 - 5:09
    or, I, I suppose is, is interesting if you
  • 5:09 - 5:11
    haven't worked in like a large enterprise
    like this.
  • 5:11 - 5:15
    But the information to power this page was
    coming
  • 5:15 - 5:17
    from a lot of different places. And our Rails
  • 5:17 - 5:19
    app was really just responsible for stitching
    that information
  • 5:19 - 5:22
    together. So, we had the product service that
    was
  • 5:22 - 5:24
    kind of serving up product catalog data, and
    then
  • 5:24 - 5:27
    we had the deals service that was kind of
  • 5:27 - 5:28
    telling us what the deals of the day were.
  • 5:28 - 5:29
    And, as I said, the Rails app was just
  • 5:29 - 5:31
    kind of there to kind of, go over here
  • 5:31 - 5:33
    and get some information. Go over here and
    get
  • 5:33 - 5:34
    some information, and then kind of plug it
    all
  • 5:34 - 5:38
    together. So when you're building an app like
    this,
  • 5:38 - 5:43
    you get this interesting phenomenon, where
    this app, on
  • 5:43 - 5:45
    its own, really can't do much at all. In
  • 5:45 - 5:48
    fact, it can't do anything. We, there wasn't,
    there
  • 5:48 - 5:51
    was probably not a single page of this app
  • 5:51 - 5:54
    that would render if those services weren't
    there.
  • 5:54 - 5:57
    So, what, this is what I mean by co-dependence.
  • 5:57 - 6:01
    This application was incredibly co-dependent
    on the ecosystem of
  • 6:01 - 6:05
    services that it lived inside of. But ideally
    we
  • 6:05 - 6:08
    don't want to be co-dependent, because we
    want to
  • 6:08 - 6:10
    be able to run this thing in isolation, to
  • 6:10 - 6:13
    test it in isolation, to debug it in isolation.
  • 6:13 - 6:16
    So, we don't want to have to stand up
  • 6:16 - 6:20
    the entire enterprise on our laptops just
    in order
  • 6:20 - 6:21
    to, to run this thing when we're, when we're
  • 6:21 - 6:24
    on a train or in a plane. So, we
  • 6:24 - 6:27
    want independence, but we're in a situation
    of co-dependence.
  • 6:27 - 6:30
    And this gets even more interesting when you
    start
  • 6:30 - 6:33
    thinking about it in terms of teams. So, in
  • 6:33 - 6:36
    our case, we had our team, let's call us
  • 6:36 - 6:40
    the red team. We're building the Rails application.
    But
  • 6:40 - 6:43
    we weren't building any of these services.
    The deals
  • 6:43 - 6:45
    services might have been maintained by the
    green team
  • 6:45 - 6:47
    and the blue team, of course, were working
    on
  • 6:47 - 6:49
    the product service.
  • 6:49 - 6:53
    And these teams were teams we sometimes, we
    didn't
  • 6:53 - 6:55
    even know where they, where they were. We
    had
  • 6:55 - 6:57
    vague ways of getting in contact with them,
    but
  • 6:57 - 6:59
    we, we didn't have a very good relationship
    with
  • 6:59 - 7:04
    them. And this leads to lots of interesting
    side-effects.
  • 7:04 - 7:06
    So one thing that you might note here is
  • 7:06 - 7:09
    the shape of the teams. Lines up pretty closely
  • 7:09 - 7:11
    with the shape of the services. So this gets
  • 7:11 - 7:15
    to this thing called Conway's Law. Don't tell
    DHH
  • 7:15 - 7:20
    that I'm talking about laws.
  • 7:20 - 7:22
    Conway's Law, coined in the 60s, says that
    the
  • 7:22 - 7:25
    communication patterns of a software system
    tend to mirror
  • 7:25 - 7:28
    the communication patterns of the people who
    build that
  • 7:28 - 7:32
    system. How many people have heard of Conway's
    Law,
  • 7:32 - 7:34
    by the way?
  • 7:34 - 7:38
    So, I'm trying to avoid calling it a law
  • 7:38 - 7:40
    but I'm not going to be able to do
  • 7:40 - 7:43
    that. I think Conway's Law is the most important
  • 7:43 - 7:47
    law for us to understand as software engineers.
    Oh,
  • 7:47 - 7:54
    I said. As people. As software writers. Sorry.
  • 7:56 - 7:59
    Conway's Law says that how people work together
    effects
  • 7:59 - 8:04
    system architecture. And, and the flip-side.
    System architecture effects
  • 8:04 - 8:09
    how people work together. And, this isn't
    kind of
  • 8:09 - 8:14
    a, a possible outcome. This is reality. This
    is
  • 8:14 - 8:18
    empirically shown for fifty years, sixty years
    almost. This
  • 8:18 - 8:20
    does happen. This is true.
  • 8:20 - 8:22
    So you can't, like, decide you don't want
    it
  • 8:22 - 8:23
    to happen. But what you can do is you
  • 8:23 - 8:27
    can either wield Conway's Law to your advantage,
    go
  • 8:27 - 8:29
    with the grain and, and use it to your
  • 8:29 - 8:31
    advantage, or you can kind of yield to Conway's
  • 8:31 - 8:32
    Law and have it beat you up.
  • 8:32 - 8:34
    So I'm gonna talk a little bit today about
  • 8:34 - 8:37
    how we wielded Conway's Law to our advantage
    rather
  • 8:37 - 8:40
    than have it beat us up.
  • 8:40 - 8:45
    So, here's our three teams. One of the most
  • 8:45 - 8:49
    fun aspects of, of working in a system that
  • 8:49 - 8:50
    has more than one team is, is when you
  • 8:50 - 8:54
    find a bug. So let's say we've got our
  • 8:54 - 8:56
    deal, deals of the day section, and we've
    noticed
  • 8:56 - 8:59
    that the prices are missing in some of the
  • 8:59 - 9:02
    deals section when we run the application.
    So now
  • 9:02 - 9:04
    we start to play this game, it's called Who's
  • 9:04 - 9:06
    Bug is it Anyway?
  • 9:06 - 9:10
    Hands up if you've played this game. Awesome.
    OK.
  • 9:10 - 9:12
    I wasn't sure if that was a cultural reference
  • 9:12 - 9:17
    that people wouldn't get. So, we know that
    the
  • 9:17 - 9:20
    deals aren't loading correctly, but is that
    the deal
  • 9:20 - 9:23
    service's fault? Maybe the product service
    isn't returning the
  • 9:23 - 9:26
    right data for those deals. Maybe we're asking
    it
  • 9:26 - 9:28
    the wrong questions. Or maybe we just have
    a
  • 9:28 - 9:32
    bug in our rendering code.
  • 9:32 - 9:35
    The fundamental issue of all of these things
    is
  • 9:35 - 9:41
    this tension between co-dependence and independence.
    We are co-dependent.
  • 9:41 - 9:45
    We want to be independent. Some people solve
    a
  • 9:45 - 9:49
    lot of these problems by embracing co-dependence.
    So, if
  • 9:49 - 9:50
    our Rails app needs the services to be up
  • 9:50 - 9:52
    and running in order to run, we'll stand up
  • 9:52 - 9:55
    the services. You can do that. You can stand
  • 9:55 - 9:57
    up copies of the services locally on your
    laptop.
  • 9:57 - 10:00
    This is more and more easy to do nowadays
  • 10:00 - 10:02
    cause we've got kind of trendy dev-ops things
    like
  • 10:02 - 10:05
    Vagrant and Chef and Puppet.
  • 10:05 - 10:07
    That will only get you so far. Try standing
  • 10:07 - 10:10
    up a bank on your laptop. It's not happening.
  • 10:10 - 10:13
    Very, very common approach here is to, to
    use
  • 10:13 - 10:16
    kind of shared services. So a shared dev environment.
  • 10:16 - 10:20
    A shared kind of staging environment. That
    kind of
  • 10:20 - 10:22
    thing. And that, that works quite well. But,
    for
  • 10:22 - 10:25
    our team, we decided to go the alternate route.
  • 10:25 - 10:29
    We wanted to, as much as possible, push for
  • 10:29 - 10:34
    independence. And, the main way we did that
    was
  • 10:34 - 10:39
    by rem- replacing our dependency on services
    with fake
  • 10:39 - 10:40
    services.
  • 10:40 - 10:45
    So, when we wanted to test our application,
    we
  • 10:45 - 10:47
    wanted to test just our application in independence.
    And
  • 10:47 - 10:49
    the way that we did that was, for each
  • 10:49 - 10:52
    of our dependent services, we replaced those
    services with
  • 10:52 - 10:56
    kind of a fake version of that service. And
  • 10:56 - 10:58
    by doing that, we were allowed to run these
  • 10:58 - 11:02
    things that, that we called bounded integration
    tests.
  • 11:02 - 11:06
    So, these were tests that tested the entire
    stack
  • 11:06 - 11:09
    of our application, of our Rails application,
    from top
  • 11:09 - 11:11
    to bottom, from kind of html all the way
  • 11:11 - 11:16
    down to the network. But, we weren't, we were
  • 11:16 - 11:20
    testing that in isolation. We weren't actually
    hitting those
  • 11:20 - 11:24
    shared services.
  • 11:24 - 11:26
    And what's really interesting here is, do
    you see
  • 11:26 - 11:29
    the, the boundary of those tests lines up
    almost
  • 11:29 - 11:32
    perfectly with the boundary of our team. So
    this
  • 11:32 - 11:34
    is a really good example of using Conway's
    Law
  • 11:34 - 11:38
    to your advantage. Embracing Conway's Law
    and shaping your
  • 11:38 - 11:42
    approach, shaping your software, with the
    shape of your
  • 11:42 - 11:44
    team. And this was something that helped us
    win.
  • 11:44 - 11:47
    So, if you want to build these fake services,
  • 11:47 - 11:49
    what are your options? Comes down to, to two
  • 11:49 - 11:52
    different kind of techniques, really. In-process
    and out-of-process. So
  • 11:52 - 11:55
    in-process means you're kind of messing around
    with the
  • 11:55 - 11:58
    actual Rails, running Rails process, and like
    replacing the
  • 11:58 - 12:01
    network stack with a fake network stack maybe.
  • 12:01 - 12:03
    Out of process means you're standing up a
    real
  • 12:03 - 12:05
    http server. It's an actual, you know, you
    can
  • 12:05 - 12:09
    actually talk to it over http. And your application,
  • 12:09 - 12:11
    your Rails app, rather than pointing to a
    real
  • 12:11 - 12:13
    deal service, it's going to point to this
    fake
  • 12:13 - 12:15
    deal service. It's gonna look and smell like
    a
  • 12:15 - 12:17
    deal service. You send it a request. It gives
  • 12:17 - 12:19
    you a response. It's not a real deals service.
  • 12:19 - 12:22
    It's a fake service that we have control over.
  • 12:22 - 12:24
    So, you can imagine if we wanted to test
  • 12:24 - 12:27
    unicode rendering, we could stand up a fake
    product
  • 12:27 - 12:30
    service that returned a product tied tool
    that was
  • 12:30 - 12:32
    all kind of snow man and that kind of
  • 12:32 - 12:35
    stuff. And, and that allows us to test how
  • 12:35 - 12:38
    we handle unicode titles without having, then,
    to need
  • 12:38 - 12:39
    a unicode title.
  • 12:39 - 12:43
    So, in process, a couple of popular options,
    vcr
  • 12:43 - 12:45
    and webmock. We actually used vcr quite heavily
    on
  • 12:45 - 12:48
    this project that I'm talking about. So basically
    it
  • 12:48 - 12:50
    just kind of sits, it kind of injects itself
  • 12:50 - 12:53
    in between your application and the network
    layer and
  • 12:53 - 12:56
    records all the interactions between your
    application and the
  • 12:56 - 12:58
    network, and then you can kind of flip it
  • 12:58 - 13:00
    into playback mode, and rather than, next
    you time
  • 13:00 - 13:02
    you go and make a, make a network call,
  • 13:02 - 13:03
    it's not actually gonna call the network.
    It's going
  • 13:03 - 13:08
    to just play back the previously recorded
    interaction. So
  • 13:08 - 13:13
    that worked out well for us with some caveats.
  • 13:13 - 13:14
    Out of process, you've got a lot more options,
  • 13:14 - 13:16
    because you're not running out of process.
    You don't
  • 13:16 - 13:19
    have to use Ruby. You can use whatever tool
  • 13:19 - 13:21
    makes the most sense. So mimic is a really
  • 13:21 - 13:24
    good option here. This is actually a Ruby
    gem
  • 13:24 - 13:28
    written by Luke Redpath. It's a Sinatra application
    that
  • 13:28 - 13:31
    pretends to be whatever you want it to be.
  • 13:31 - 13:33
    Outside of the Ruby community, or outside
    of the
  • 13:33 - 13:37
    Ruby language, I suppose, there's a library
    called moco.
  • 13:37 - 13:41
    It's quite powerful. Stubby is another one.
    And then
  • 13:41 - 13:45
    there's this interesting one called montebank.
    What makes montebank
  • 13:45 - 13:48
    interesting is it doesn't just fake out http,
    it
  • 13:48 - 13:50
    will fake out whatever protocol you want.
    So it
  • 13:50 - 13:52
    can fake out smtp to it, so you can
  • 13:52 - 13:54
    check emails. It'll fake out web sockets.
    That kind
  • 13:54 - 13:57
    of stuff. So that's an interesting one to
    look
  • 13:57 - 13:59
    at.
  • 13:59 - 14:02
    So now we've got these bounded integration
    tests. And
  • 14:02 - 14:05
    that means we have some confidence that it
    wasn't
  • 14:05 - 14:08
    us that, that's creating this bug. Because
    our bounded
  • 14:08 - 14:11
    integration tests are passing. So all was
    happy and
  • 14:11 - 14:13
    we can go on with our day.
  • 14:13 - 14:16
    Well, obviously not, because we actually still
    don't know
  • 14:16 - 14:18
    where the bug is. And the goal here is
  • 14:18 - 14:21
    not for us to kind of, prove that we,
  • 14:21 - 14:23
    it's not our fault. The goal is to identify
  • 14:23 - 14:25
    the problem and fix it, because at the end
  • 14:25 - 14:27
    of the day it's a system. We're a part
  • 14:27 - 14:28
    of that system and we need to fix the
  • 14:28 - 14:31
    system and move on.
  • 14:31 - 14:33
    So, so we're left saying, OK. We know it's
  • 14:33 - 14:36
    not our fault. We'd like to help our, our
  • 14:36 - 14:41
    comrades on other teams figure out where the
    problem
  • 14:41 - 14:43
    is. And for that we used a technique called
  • 14:43 - 14:49
    contract tests. So, contract tests, also sometimes
    referred to
  • 14:49 - 14:55
    as consumer-driven contracts. The idea with
    these is we
  • 14:55 - 15:00
    write test code that expresses what we expect
    a
  • 15:00 - 15:03
    dependency, an external service to do, and
    then we
  • 15:03 - 15:05
    run those tests against a real version of
    that
  • 15:05 - 15:07
    service, and we find out if that service actually
  • 15:07 - 15:11
    does what we expect. Quite simple.
  • 15:11 - 15:13
    What's weird is we're testing someone else's
    code. We're
  • 15:13 - 15:17
    not testing our code. We're, we're writing
    tests, but
  • 15:17 - 15:22
    we're testing another team's services. So
    here's, again, our
  • 15:22 - 15:27
    boundary, our bounded integration tests. And,
    so we verified
  • 15:27 - 15:29
    that the way that the Rails app is, that
  • 15:29 - 15:31
    the Rails app does the right thing when it
  • 15:31 - 15:34
    talks to what we think these services are
    doing.
  • 15:34 - 15:37
    Contract tests, once we add these, actually
    verify that
  • 15:37 - 15:39
    what the service does is what we think it's
  • 15:39 - 15:40
    gonna do.
  • 15:40 - 15:42
    Cause it could be that there's a bug in
  • 15:42 - 15:45
    the service, and these tests will find those
    bugs,
  • 15:45 - 15:46
    hopefully, because we'll ask it to do something
    and
  • 15:46 - 15:48
    it won't do what we expect. There could be
  • 15:48 - 15:51
    a bug in our understanding of the service,
    and
  • 15:51 - 15:53
    that's why these are called contract tests,
    because they
  • 15:53 - 15:55
    define a contract between our team and the
    other
  • 15:55 - 16:00
    team. Again, Conway's Law is coming in here.
  • 16:00 - 16:02
    How many of you have worked with an external
  • 16:02 - 16:05
    service where the, the Wiki page that documented
    the
  • 16:05 - 16:09
    API was out of date? How many of you
  • 16:09 - 16:11
    have ever worked on a service where it wasn't
  • 16:11 - 16:17
    wrong? It's always wrong. And that's OK. Documentation
    tends
  • 16:17 - 16:19
    to be stale. API documentation I think is
    never
  • 16:19 - 16:23
    not stale. It just is born that way.
  • 16:23 - 16:25
    These contract tests are a way to, to, to
  • 16:25 - 16:29
    mitigate that. Because you're expressing your
    expectations in code
  • 16:29 - 16:33
    rather than in words.
  • 16:33 - 16:36
    So we, on, on my, on my team, we
  • 16:36 - 16:38
    wrote contract tests for every single one
    of our
  • 16:38 - 16:41
    dependencies. This was the most productive
    thing we did
  • 16:41 - 16:44
    on this team is, in terms of improving efficiency
  • 16:44 - 16:49
    of, of us creating software. It really, really
    helped
  • 16:49 - 16:51
    us nail down, whenever there was an issue,
    where
  • 16:51 - 16:54
    that issue was. And it really helped us communicate
  • 16:54 - 16:56
    with, with our friends on other teams.
  • 16:56 - 16:59
    So, if you want to do these, you've got
  • 16:59 - 17:00
    a few different options for contract tests.
    We actually
  • 17:00 - 17:04
    just did plain old RSpec. We just used standard
  • 17:04 - 17:07
    RSpec test runner to make network calls to
    our
  • 17:07 - 17:09
    dependencies and then look at the results
    and make
  • 17:09 - 17:11
    sure that things looked the way that we expected
  • 17:11 - 17:12
    them to look.
  • 17:12 - 17:15
    There's two more kind of sophisticated options
    out there.
  • 17:15 - 17:18
    There's a gem called pacto and another gem
    called
  • 17:18 - 17:21
    pact. And these are kind of like real power
  • 17:21 - 17:25
    tools. They're quite sophisticated. They're,
    they're very fully-featured. If
  • 17:25 - 17:26
    you want to really kind of get into this,
  • 17:26 - 17:29
    into this mind set.
  • 17:29 - 17:31
    So once we had these bounded integration tests
    and
  • 17:31 - 17:34
    these contract tests, we were left with this
    kind
  • 17:34 - 17:39
    of CI dashboard that looked something like
    this. So
  • 17:39 - 17:41
    whenever we checked in code, we'd run our
    unit
  • 17:41 - 17:43
    tests, we'd run our functional tests. And
    assuming those
  • 17:43 - 17:45
    passed, we'd run our kind of bounded integration
    tests
  • 17:45 - 17:46
    up there at the top right.
  • 17:46 - 17:51
    Assuming those passed, we'd then run our end-to-end
    tests.
  • 17:51 - 17:54
    So these were running, testing as much of
    the
  • 17:54 - 17:57
    stack as we could possibly stand up. So, our
  • 17:57 - 18:00
    code, our team's code, maybe our team's dependency's
    code.
  • 18:00 - 18:03
    So as much of the stack as possible. So
  • 18:03 - 18:05
    really verifying, from a user's point of view,
    that
  • 18:05 - 18:09
    this, this system worked as we expected.
  • 18:09 - 18:11
    In theory, this was the picture. In reality
    it
  • 18:11 - 18:15
    was almost never green. That was OK. So, this
  • 18:15 - 18:17
    is what things looked like a lot of the
  • 18:17 - 18:21
    time. Our tests were passing, the end-to-end
    tests were
  • 18:21 - 18:24
    failing. If that was the end of the story,
  • 18:24 - 18:27
    we'd be left constantly fighting fires of,
    why is
  • 18:27 - 18:29
    it not working in product- or, why is it
  • 18:29 - 18:31
    not working in staging? And is it the deals
  • 18:31 - 18:33
    service or the product service, blah, blah,
    blah.
  • 18:33 - 18:35
    But we had these contract tests. So now we
  • 18:35 - 18:38
    can see here that service D's contract tests
    seem
  • 18:38 - 18:40
    to be failing. So we've got some end-to-end
    tests
  • 18:40 - 18:44
    that are failing. This contract is failing.
    That's where
  • 18:44 - 18:46
    we can start looking for, for the cause of
  • 18:46 - 18:47
    this problem.
  • 18:47 - 18:49
    So this is what we spent a lot of
  • 18:49 - 18:50
    our time, not a lot of our time doing,
  • 18:50 - 18:53
    but this was a very frequent occurrence. The
    build
  • 18:53 - 18:54
    would go red. We'd have a look at our
  • 18:54 - 18:58
    dashboard. Oh, it's service D, again. Service
    D, you
  • 18:58 - 19:00
    guys.
  • 19:00 - 19:03
    So we go to our CI system and we
  • 19:03 - 19:07
    would look at the logs. We'd get the log
  • 19:07 - 19:09
    data that showed the request we were sending
    the
  • 19:09 - 19:12
    response we, we got back. And we'd have a
  • 19:12 - 19:13
    look and say, yup. It looks like they've broken
  • 19:13 - 19:15
    it again. They forgot to turn on the database
  • 19:15 - 19:19
    after doing a deployment, again. And we would
    write
  • 19:19 - 19:20
    an email to them saying, hey, I think it's
  • 19:20 - 19:23
    probably a bug in our code, but we've noticed
  • 19:23 - 19:25
    when we send this request we get back this
  • 19:25 - 19:29
    500 error from your service, I don't know
    what's
  • 19:29 - 19:30
    going on there.
  • 19:30 - 19:33
    You can tell I'm a consultant.
  • 19:33 - 19:37
    And, things moved a lot smoother. It, it wasn't
  • 19:37 - 19:39
    all kind of rainbows and unicorns, but it
    was
  • 19:39 - 19:40
    a lot better than if these tests hadn't have
  • 19:40 - 19:43
    been there. We would have still ended up telling
  • 19:43 - 19:44
    them and they would have fixed it, but it
  • 19:44 - 19:46
    would have sucked a lot more of our time.
  • 19:46 - 19:49
    So that's all the hand wave-y, let's all work
  • 19:49 - 19:52
    as teams stuff. Let's talk about how we're
    actually
  • 19:52 - 19:57
    gonna build this, this inside of our team.
  • 19:57 - 19:58
    So I want to talk about this idea called
  • 19:58 - 20:01
    service gateways. The main thing I'm gonna
    talk about
  • 20:01 - 20:04
    with service gateways is this gem called faraday.
    And
  • 20:04 - 20:06
    in order to talk about this gem called faraday,
  • 20:06 - 20:08
    I need to talk about this other gem called
  • 20:08 - 20:09
    rack.
  • 20:09 - 20:11
    So, how many of you know what rack is?
  • 20:11 - 20:13
    Yeah, everyone knows what rack is. How many
    of
  • 20:13 - 20:15
    you hate people that ask you raise your hands
  • 20:15 - 20:19
    when you're in the audience? I have all the
  • 20:19 - 20:23
    power. You guys have the power but don't realize
  • 20:23 - 20:24
    that.
  • 20:24 - 20:28
    So, rack is this awesome abstraction over
    http servers.
  • 20:28 - 20:32
    And the main idea, the main thing that makes
  • 20:32 - 20:36
    rack awesome is, by abstracting over the concept
    of
  • 20:36 - 20:38
    a request and the concept of a response, we
  • 20:38 - 20:41
    can kind of stack these middleware components
    in between
  • 20:41 - 20:46
    our application, and the, the underlying http
    server.
  • 20:46 - 20:49
    So, as a request comes in, from the outside
  • 20:49 - 20:55
    world, it travels through this stack of middleware.
    So,
  • 20:55 - 20:58
    each piece of middleware can, as this request
    is
  • 20:58 - 21:04
    traveling through, has the opportunity to
    kind of modify,
  • 21:04 - 21:06
    modify the request and kind of transform it
    in
  • 21:06 - 21:09
    some way, add some information to the request,
    or
  • 21:09 - 21:11
    to kind of have some side-effect.
  • 21:11 - 21:13
    And then, a Rails app is gonna deal with
  • 21:13 - 21:16
    that request and then, and then send back
    a
  • 21:16 - 21:18
    response. And, again, as that response is
    traveling back
  • 21:18 - 21:24
    up through the pipeline, through the, the
    middleware stacks,
  • 21:24 - 21:27
    again, each of those pieces of middleware
    can modify
  • 21:27 - 21:29
    that request in some way, can add some information
  • 21:29 - 21:32
    to it or can have some side effect.
  • 21:32 - 21:36
    Rails loves rack. So this is the, the kind
  • 21:36 - 21:41
    of the stop stack of rack middlewares that
    comes
  • 21:41 - 21:43
    when you, when you just do rails generate
    new
  • 21:43 - 21:47
    project. So, yeah. Pretty, pretty popular.
    And the reason
  • 21:47 - 21:48
    that this is popular is because the guys that
  • 21:48 - 21:50
    built rack are smart and the guys that, guys
  • 21:50 - 21:52
    and gals, excuse me, that built rack are smart
  • 21:52 - 21:56
    and, likewise, Rails. And they realized that
    this is
  • 21:56 - 21:58
    a very powerful abstraction and so they're
    really leveraging
  • 21:58 - 22:00
    this power.
  • 22:00 - 22:02
    So why was I talking about rack when I
  • 22:02 - 22:05
    was supposed to be talking about faraday?
    Faraday is
  • 22:05 - 22:08
    the exact same idea of rack, but applied for
  • 22:08 - 22:11
    an http client. So, again, we have this abstraction
  • 22:11 - 22:14
    over request and response. This time in the
    context
  • 22:14 - 22:16
    of making a request and receiving a response
    rather
  • 22:16 - 22:19
    than receiving a request and sending back
    a response.
  • 22:19 - 22:23
    And, again, we can stack these pieces of middleware
  • 22:23 - 22:28
    in between our application and the underlying
    network library.
  • 22:28 - 22:30
    So, in this case, it's us making a request.
  • 22:30 - 22:33
    So, as we send the request out to the
  • 22:33 - 22:36
    network, again, that request travels through
    all of these
  • 22:36 - 22:38
    middlewares, and these middlewares, again,
    have the opportunity to
  • 22:38 - 22:41
    either modify that request in some way, have
    a
  • 22:41 - 22:44
    side effect, add some information to the request.
    Eventually
  • 22:44 - 22:45
    it gets on the wire. Eventually it gets to
  • 22:45 - 22:47
    our dependency. Hopefully not service D because
    they'll probably
  • 22:47 - 22:50
    go down again.
  • 22:50 - 22:54
    And then service D hopefully sends a response,
    and
  • 22:54 - 22:57
    again, as that response travels back through
    the stack,
  • 22:57 - 23:01
    the stack is able to modify that, that response
  • 23:01 - 23:03
    as it comes through, add some information.
    Have a
  • 23:03 - 23:05
    side effect.
  • 23:05 - 23:08
    So, how do we use this thing? So here's
  • 23:08 - 23:10
    a, this is a service gateway. This is a
  • 23:10 - 23:14
    class that represents a, a connection to the
    outside
  • 23:14 - 23:19
    world. Here's us building a faraday middleware
    stack. So
  • 23:19 - 23:24
    we're building a connection. We're saying
    hey, new faraday.
  • 23:24 - 23:26
    Please use the instrumentation middleware
    and do some JSON
  • 23:26 - 23:31
    stuff and follow redirects and do some logging.
  • 23:31 - 23:34
    And that's it. We've now got a faraday connection.
  • 23:34 - 23:37
    This is how we use a faraday connection. So,
  • 23:37 - 23:40
    we say, hey, faraday connection, hey, http
    client, we
  • 23:40 - 23:43
    want to get this url, or this path. And
  • 23:43 - 23:46
    we get a response back. Pretty simple stuff.
    I
  • 23:46 - 23:48
    would say this is readable code. DHH would
    be
  • 23:48 - 23:50
    pleased with me.
  • 23:50 - 23:52
    And what's really nice, the real power of,
    of
  • 23:52 - 23:54
    faraday, is there's all this extra stuff that
    we
  • 23:54 - 23:59
    set up, this middleware, this technical junk
    going on.
  • 23:59 - 24:01
    But our, the rest of our code doesn't have
  • 24:01 - 24:03
    to care about it. So we've kind of abstracted
  • 24:03 - 24:08
    over all of that stuff of JSON, following
    redirects
  • 24:08 - 24:12
    and logging and caching.
  • 24:12 - 24:13
    So we used faraday a lot in these things
  • 24:13 - 24:19
    that, that I was calling service gateways.
    So the,
  • 24:19 - 24:21
    as I said, the really nice thing about things
  • 24:21 - 24:22
    like rack and faraday is they allow us to
  • 24:22 - 24:29
    segregate the boring tech-y stuff, http, logging,
    caching, instrumentation,
  • 24:29 - 24:31
    the stuff that computer people talk about
    at conferences
  • 24:31 - 24:34
    like this, from the business domain, which
    is the
  • 24:34 - 24:36
    stuff that people actually care about.
  • 24:36 - 24:39
    So, these service gateways acted as the place
    where
  • 24:39 - 24:43
    we pushed all of the boring techy goop out
  • 24:43 - 24:46
    to the boundaries of our system, so the core
  • 24:46 - 24:49
    of our system, the core of our Rails application,
  • 24:49 - 24:54
    wasn't talking about JSON requests, urls,
    caching, logging, deserialization.
  • 24:54 - 24:57
    It was talking about books and products and
    prices.
  • 24:57 - 25:01
    Things that our application really should
    be caring about.
  • 25:01 - 25:07
    So this is this idea of hexagonal architectures.
    Push
  • 25:07 - 25:09
    all of the goopy boring techy stuff out to
  • 25:09 - 25:11
    the boundaries of your system, so that the
    core
  • 25:11 - 25:15
    of your system can focus on the domain. The
  • 25:15 - 25:17
    stuff that you really care about. The stuff
    that
  • 25:17 - 25:23
    makes your system valuable to other people.
  • 25:23 - 25:24
    So what kind of things did we put into
  • 25:24 - 25:26
    these? What kind of stuff, boring techy stuff
    did
  • 25:26 - 25:31
    we isolate in these service gateways? One
    thing that
  • 25:31 - 25:36
    we did was we isolated serialization. So,
    serialization means
  • 25:36 - 25:40
    JSON parsing or, in our case, XML parsing,
    cause
  • 25:40 - 25:44
    we were in an enterprise. Yay.
  • 25:44 - 25:47
    Comes down to the same thing actually. So,
    when
  • 25:47 - 25:49
    we talk about parsing JSON or XML, we're actually
  • 25:49 - 25:52
    talking about two different things. And I
    think often
  • 25:52 - 25:56
    we conflate these two. So, step one, is we
  • 25:56 - 25:58
    have this stream of bytes or this raw string,
  • 25:58 - 25:59
    and we want to turn it into this kind
  • 25:59 - 26:03
    of generic structure, like a hash of arrays
    of,
  • 26:03 - 26:05
    of objects, right. So that's, that's something,
    you know.
  • 26:05 - 26:07
    You do JSON dot parse or whatever and you
  • 26:07 - 26:09
    get this kind of generic data structure out.
  • 26:09 - 26:14
    But, if we are following the principles of
    hexagonal
  • 26:14 - 26:17
    architecture, we don't want to deal with JSON
    data
  • 26:17 - 26:19
    structures or generic data structures. We
    want to deal
  • 26:19 - 26:22
    with products and books and deals. So the
    next
  • 26:22 - 26:24
    step is to actually take that generic structure
    and
  • 26:24 - 26:27
    map it into a domain object that we actually
  • 26:27 - 26:27
    want to work with.
  • 26:27 - 26:30
    Cause our goal here is to stop talking about
  • 26:30 - 26:33
    things like JSON as quickly as possible, at
    the
  • 26:33 - 26:35
    boundaries of our system, and start talking
    about products
  • 26:35 - 26:40
    and prices and deals. So this is two steps.
  • 26:40 - 26:43
    So, the other thing that you'll, I noticed
    working
  • 26:43 - 26:47
    particularly in larger organizations, is these
    responses that you
  • 26:47 - 26:50
    get back are huge. And really, often times,
    you
  • 26:50 - 26:52
    only really care about a small subset of the
  • 26:52 - 26:54
    response you get back. So you get back this
  • 26:54 - 26:57
    big chunk of bytes. You turn it into this
  • 26:57 - 26:59
    big generic structure, and then you actually
    just want
  • 26:59 - 27:01
    to pluck three or four or five or six
  • 27:01 - 27:03
    things out of that structure, that represent
    the product
  • 27:03 - 27:05
    in your, in your domain.
  • 27:05 - 27:07
    You don't care about the, the short description.
    You
  • 27:07 - 27:10
    certainly don't care about the response time.
    Really all
  • 27:10 - 27:12
    you care about is the, you know, the title
  • 27:12 - 27:14
    or the author, you know, that kind of thing.
  • 27:14 - 27:17
    So there's some gems that can help you make
  • 27:17 - 27:19
    this easier. So, very popular one is this
    thing
  • 27:19 - 27:21
    called hashie. Hashie will just make it a
    little
  • 27:21 - 27:23
    bit easier for you to work with these generic
  • 27:23 - 27:24
    data structures. But at the end of the day,
  • 27:24 - 27:27
    they're still generic data structures.
  • 27:27 - 27:31
    The second step that we took was to take
  • 27:31 - 27:33
    all of that boring boiler plate that we were
  • 27:33 - 27:35
    doing of saying, you know, get this dot that
  • 27:35 - 27:38
    dot the other thing and get me the price.
  • 27:38 - 27:39
    And then this dot that dot the other thing,
  • 27:39 - 27:42
    get me the, the offer details. And turn that
  • 27:42 - 27:44
    into a declarative statement that we could
    just make
  • 27:44 - 27:46
    at the top of a class that would make
  • 27:46 - 27:46
    these things.
  • 27:46 - 27:49
    So we turn that mapping, that boring boilerplate
    mapping,
  • 27:49 - 27:52
    into something that was declarative rather
    than imperative. We
  • 27:52 - 27:56
    actually ended up extracting that little library
    that we
  • 27:56 - 27:59
    built into this thing called lazy_doc. There's
    another couple
  • 27:59 - 28:01
    of gems that are very, that have very similar
  • 28:01 - 28:04
    goals. Embedded_doc is another one. And there's
    this really
  • 28:04 - 28:09
    quite powerful one called representable, which
    is very good.
  • 28:09 - 28:11
    It's, it's very powerful. It almost does too
    many
  • 28:11 - 28:13
    things for my taste, but it's definitely,
    definitely a
  • 28:13 - 28:15
    good option.
  • 28:15 - 28:17
    The reason, by the way, embedded_doc is called
    embedded_doc
  • 28:17 - 28:19
    is cause it's, what we're kind of talking
    about
  • 28:19 - 28:22
    here is this embedded document pattern. That's
    the name
  • 28:22 - 28:24
    of the pattern. Sorry, now I'm talking about
    patterns.
  • 28:24 - 28:28
    I'm really off-message.
  • 28:28 - 28:30
    So what else did we put in our faraday
  • 28:30 - 28:36
    stack? Caching. This is the most, for me,
    the
  • 28:36 - 28:39
    most exciting thing to talk about. So let
    me
  • 28:39 - 28:41
    talk about it. So, back to our example, let's
  • 28:41 - 28:44
    say we've got our Rails app. And we've got
  • 28:44 - 28:47
    our product service and we've got this pricing
    service.
  • 28:47 - 28:49
    Fun fact that I didn't know before I worked
  • 28:49 - 28:51
    on this application. Prices can change, like,
    multiple times
  • 28:51 - 28:54
    a minute in some of these systems. They're
    really
  • 28:54 - 28:57
    trying to optimize for prices.
  • 28:57 - 29:02
    So, can't really cache pricing information.
    Product information tends
  • 29:02 - 29:04
    to be pretty static. The author of a book
  • 29:04 - 29:06
    doesn't change very often. The title of a
    book
  • 29:06 - 29:10
    doesn't change very often. But we're always
    looking up
  • 29:10 - 29:12
    this product information, almost every single
    request. So let's
  • 29:12 - 29:14
    cache that. Let's make this performant.
  • 29:14 - 29:17
    So, a lot of you are automatically starting
    to
  • 29:17 - 29:19
    think about how we would implement this and,
    well,
  • 29:19 - 29:21
    we would have a product cache, and then when
  • 29:21 - 29:22
    we need a product we'll go to the cache,
  • 29:22 - 29:25
    and if it's there, then we'll check the freshness.
  • 29:25 - 29:27
    And if the freshness is up to some configured
  • 29:27 - 29:29
    thing, then we'll get it. Otherwise we'll
    go to
  • 29:29 - 29:30
    the network. And then when we get back from
  • 29:30 - 29:32
    network, put it in the cache, blah, blah,
    blah.
  • 29:32 - 29:35
    All of this stuff, right. And we're, we're
    back
  • 29:35 - 29:37
    to thinking about boring technical goop and
    we're not
  • 29:37 - 29:40
    talking about our domain anymore. We didn't
    want to
  • 29:40 - 29:45
    do this. I'm, honestly, bored with getting
    caching wrong
  • 29:45 - 29:47
    over and over again in each of my applications.
  • 29:47 - 29:49
    And so, we just pretended to be a web
  • 29:49 - 29:51
    browser.
  • 29:51 - 29:54
    As web developers, we know that images are
    very
  • 29:54 - 29:56
    cacheable, and we should put caching headers
    on our,
  • 29:56 - 29:59
    on our images, so that the browser can do
  • 29:59 - 30:00
    the right thing and cache this so that every
  • 30:00 - 30:02
    time we want to get this image, if it's
  • 30:02 - 30:04
    already in the cache, we don't have to go
  • 30:04 - 30:09
    onto the network. Kind of very common practice.
  • 30:09 - 30:13
    We don't write JavaScript cache repositories
    and then go
  • 30:13 - 30:14
    and check and see if the image is in
  • 30:14 - 30:16
    there and then, if it's not, we'll go to
  • 30:16 - 30:17
    the network and then put it in the cache
  • 30:17 - 30:18
    repository.
  • 30:18 - 30:20
    The web browser just does this for us. All
  • 30:20 - 30:22
    we need to do is set the caching headers
  • 30:22 - 30:27
    on this, this ping. So, my argument is, and
  • 30:27 - 30:29
    what we did was, just apply the same principle
  • 30:29 - 30:33
    to our API. So product dot, or product slash
  • 30:33 - 30:36
    wherever this is at - my pretend url for,
  • 30:36 - 30:40
    for this product. We had caching headers on
    this
  • 30:40 - 30:44
    API call, that said this, this url is cacheable
  • 30:44 - 30:47
    for twenty minutes.
  • 30:47 - 30:50
    In our faraday stack, we had a caching middleware.
  • 30:50 - 30:53
    So, the first time that we requested that
    url
  • 30:53 - 30:55
    for that product, first time we wanted that
    product,
  • 30:55 - 30:57
    our Rails app would say to our service gateway,
  • 30:57 - 30:59
    I want this product. The service gateway would
    say,
  • 30:59 - 31:02
    OK, it's at this url. I'm gonna make a
  • 31:02 - 31:05
    request through my faraday stack for that
    url.
  • 31:05 - 31:08
    That request would go through our stack, and
    the
  • 31:08 - 31:10
    response would go through our response on
    the way
  • 31:10 - 31:11
    back, and the caching layer would say, oh
    look
  • 31:11 - 31:14
    at that. There's this caching header on this
    JSON
  • 31:14 - 31:15
    that says it's gonna be valid for twenty minutes.
  • 31:15 - 31:17
    Let me just put this response in my little
  • 31:17 - 31:19
    cache on disk here.
  • 31:19 - 31:24
    And, five minutes later, another user comes
    in and
  • 31:24 - 31:26
    wants to, by chance, look at the same product.
  • 31:26 - 31:30
    Again, our service gateway, our code doesn't
    do anything
  • 31:30 - 31:32
    different. It just says, hey, service gateway,
    I want
  • 31:32 - 31:35
    this product. Our service gateway doesn't
    do anything different.
  • 31:35 - 31:37
    It just says to faraday, hey, I want to
  • 31:37 - 31:39
    get this url.
  • 31:39 - 31:41
    The request comes through to the caching layer.
    The
  • 31:41 - 31:44
    caching layer says, oh look. That's the same
    url
  • 31:44 - 31:46
    I just pulled five minutes, and the, the caching
  • 31:46 - 31:48
    headers say it's valid for twenty minutes.
    I'll just
  • 31:48 - 31:50
    return what I've got in my local cache. I
  • 31:50 - 31:53
    won't go on the network. I won't bother with
  • 31:53 - 31:56
    all that stuff. I'll just read it from the
  • 31:56 - 31:57
    disc.
  • 31:57 - 31:59
    This is what web browsers do all the time.
  • 31:59 - 32:01
    We can do this all this time with, literally,
  • 32:01 - 32:05
    a single line of code. Sorry. That's not a
  • 32:05 - 32:09
    single line. It's a single method call. Would
    be
  • 32:09 - 32:10
    a single line, I guess everything could be
    a
  • 32:10 - 32:14
    single line of code, right.
  • 32:14 - 32:19
    So, we've just said to our faraday stack,
    hey,
  • 32:19 - 32:21
    add some caching middleware. Write it to disc
    at
  • 32:21 - 32:24
    this location, and there we go. We, we've
    now
  • 32:24 - 32:27
    got all the semantics of a web browser. And,
  • 32:27 - 32:29
    we didn't have to do any work apart from
  • 32:29 - 32:33
    this single method call. And what's really
    powerful is
  • 32:33 - 32:38
    the team that knows the most about the data,
  • 32:38 - 32:40
    so the product team in this case, can define
  • 32:40 - 32:43
    the caching semantics of their data.
  • 32:43 - 32:46
    So, if they realized, like, you know what,
    these,
  • 32:46 - 32:48
    this, the name of the author keeps on changing.
  • 32:48 - 32:52
    We need to drop down the caching freshness,
    they
  • 32:52 - 32:54
    can just say, you know what, it's gonna be
  • 32:54 - 32:57
    ten minutes. And we just get that semantics,
    we
  • 32:57 - 33:00
    just start, we change our caching rules. No,
    no
  • 33:00 - 33:03
    code change. No configuration change. No redeployment.
    It just
  • 33:03 - 33:04
    happens.
  • 33:04 - 33:07
    So, again, Conway's Law. The team that knows
    the
  • 33:07 - 33:10
    most about the data has control over the caching
  • 33:10 - 33:16
    of that data. Really, really, really powerful
    stuff.
  • 33:16 - 33:19
    This goes back to this principle that, that
    I'm
  • 33:19 - 33:21
    really passionate about. I think a lot of
    times
  • 33:21 - 33:23
    we, we, we, we think of ourselves as building
  • 33:23 - 33:25
    these systems on the web. We, we're building
    our
  • 33:25 - 33:28
    stuff on top of http. I don't think we
  • 33:28 - 33:29
    should be doing that. I think we should be
  • 33:29 - 33:32
    building systems that are of the web.
  • 33:32 - 33:37
    So, we should be using principles like, like
    REST,
  • 33:37 - 33:43
    like hypermedia, like caching, http caching,
    because these, these
  • 33:43 - 33:46
    are the principles that have made the most
    successful,
  • 33:46 - 33:50
    biggest distributed system in the world work.
    It's really
  • 33:50 - 33:53
    messy, and sometimes it's a bit of a pain
  • 33:53 - 33:56
    to use, but it works really well, and it's
  • 33:56 - 33:59
    all done for us already. We don't have to
  • 33:59 - 34:01
    figure this stuff out ourselves. It's all
    out there
  • 34:01 - 34:04
    and it's been working for decades.
  • 34:04 - 34:06
    We use it, in some cases, hypermedia is something
  • 34:06 - 34:09
    we're starting to understand more and more.
    We can
  • 34:09 - 34:11
    use it in more places. Caching is, is an
  • 34:11 - 34:13
    example of that.
  • 34:13 - 34:17
    So, some principles. I could have talked about
    all
  • 34:17 - 34:19
    this stuff for hours and hours and hours,
    but
  • 34:19 - 34:20
    I don't have time to do that. So I'm
  • 34:20 - 34:22
    just gonna shove a bunch of words at the
  • 34:22 - 34:26
    end of this talk, and, and hope that, that
  • 34:26 - 34:28
    if they're new words to you that you go
  • 34:28 - 34:30
    out and, and research them.
  • 34:30 - 34:33
    Conway's Law is, is the big one. This is
  • 34:33 - 34:36
    something I'm really passionate about. If
    you, software, building
  • 34:36 - 34:39
    software today is very much a team sport.
    If
  • 34:39 - 34:41
    you don't understand how to work with other
    teams,
  • 34:41 - 34:43
    then someone else is gonna do it better than
  • 34:43 - 34:45
    you. So this is important stuff.
  • 34:45 - 34:48
    Domain-Driven Design, I kind of touched on
    this talking
  • 34:48 - 34:52
    about domain objects and talking about kind
    of bounded
  • 34:52 - 34:54
    contexts. It's a really, really good book.
    It's really,
  • 34:54 - 34:58
    really hard to read. Eric Evans is an incredibly
  • 34:58 - 35:00
    smart guy who's not necessarily the best at
    kind
  • 35:00 - 35:03
    of succinctly expressing ideas.
  • 35:03 - 35:05
    If you do get this book, read the second
  • 35:05 - 35:08
    half before you read the first half. He himself
  • 35:08 - 35:09
    has said he got the order around wrong in
  • 35:09 - 35:11
    retrospect. The, the second half has loads
    of really
  • 35:11 - 35:13
    good stuff in it. The first half does too.
  • 35:13 - 35:15
    But the second half, I think, is where the
  • 35:15 - 35:17
    real, the real, real great stuff is.
  • 35:17 - 35:21
    Postel's Law. I didn't really talk about this
    at
  • 35:21 - 35:24
    all. But if you're building SOA systems, this
    is
  • 35:24 - 35:28
    the way that you evolve these systems over
    time,
  • 35:28 - 35:31
    without having to redeploy your entire enterprise
    at once.
  • 35:31 - 35:34
    So, Postel's Law is very, very valuable. Another
    reason
  • 35:34 - 35:37
    why the web has been so successful is Postel's
  • 35:37 - 35:41
    Law. html is incredibly permissive. It draws,
    it causes
  • 35:41 - 35:43
    a bunch of pain, but it also is the
  • 35:43 - 35:46
    reason why html is the system that we still
  • 35:46 - 35:47
    use today.
  • 35:47 - 35:50
    Hexagonal architectures. Talked about this
    a fair bit. This
  • 35:50 - 35:52
    is a really, really important principle. I'm
    really excited
  • 35:52 - 35:54
    that the Rails community is starting to kind
    of
  • 35:54 - 35:56
    get, to get excited about this. But it's been
  • 35:56 - 35:58
    around for awhile. There's loads of really
    good talks
  • 35:58 - 36:01
    out there about hexagonal architectures as
    they apply to
  • 36:01 - 36:02
    Rails. There's been a couple of talks at the
  • 36:02 - 36:04
    conference already.
  • 36:04 - 36:05
    There's a, there's a Birds of a Feather session
  • 36:05 - 36:09
    tonight about it, I believe. So there's loads
    of
  • 36:09 - 36:11
    res- loads of good resources out there. Not
    just
  • 36:11 - 36:14
    for Rails specifically, but just, hexagonal
    architectures in general.
  • 36:14 - 36:17
    Because it is a general architectural principle.
  • 36:17 - 36:21
    Finally, we should be embracing the web. It's
    been
  • 36:21 - 36:23
    around for a long time. The patterns are very
  • 36:23 - 36:26
    well understood, very well established. The
    tooling is amazingly
  • 36:26 - 36:30
    powerful. We keep on reinventing wheels. Let's
    not keep
  • 36:30 - 36:33
    reinventing this particular wheel. When it
    makes sense to
  • 36:33 - 36:35
    make the web and the principles of the web,
  • 36:35 - 36:36
    we should be doing that.
  • 36:36 - 36:37
    Thank you.
Title:
RailsConf 2014 - Rails as an SOA Client by Pete Hodgson
Description:

more » « less
Duration:
37:04

English subtitles

Revisions