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

A Gentle Walk Towards SOA

A Gentle Walk Towards SOA

Many smaller projects with limited complexity can easily be served by an application written on top of your favorite monolithic framework. But as complexity and scope increase you will often find increased load times and significant barriers to testing by way of heavy coupling of both your application code and your data.

How do you approach this problem when you need to scale beyond the capabilities of a monolithic application? The concepts involved are rather simple and have been around for a very long time. But the path from monolithic application to a service-based architecture is not easy with existing projects. The answer is not to create many HTTP-based services tomorrow; the answer is to move iteratively through your codebase. In this talk we will look at how to approach this problem by teasing data and concerns into separated services in a step by step fashion.

Jeff Carouth

April 18, 2015
Tweet

More Decks by Jeff Carouth

Other Decks in Programming

Transcript

  1. PRESENTED BY
    JEFF CAROUTH
    @jcarouth
    A Gentle Walk
    Towards SOA

    View full-size slide

  2. Welcome to the 6-hour
    tutorial on service
    oriented and network-
    based application
    architectures.

    View full-size slide

  3. Agenda
    • What problem are we solving?

    • Why do I need an SOA?

    • How can I implement this in my existing ball of mud
    architecture?

    View full-size slide

  4. Application Architecture

    View full-size slide

  5. Most application
    developers go through
    a progression of
    understanding of
    architecture.

    View full-size slide

  6. Architectures

    View full-size slide

  7. Architectures

    View full-size slide

  8. Architectures
    libs

    View full-size slide

  9. Architectures
    libs models
    controllers
    views

    View full-size slide

  10. Architectures
    End User
    Application
    Business Logic
    Database

    View full-size slide

  11. Architectures
    End User
    Application
    Business Logic
    Database
    Controllers
    Models
    Views

    View full-size slide

  12. The Monolithic app
    End User
    Application
    Business Logic
    Database

    View full-size slide

  13. The Monolithic app
    End User
    Application
    Business Logic
    Database

    View full-size slide

  14. After nearly a decade of
    life, this monolith has
    58 controllers and
    153 models.

    View full-size slide

  15. Adding a new feature
    likely means adding new
    controllers and new
    models.

    View full-size slide

  16. Modifying existing
    models changes other
    models; changes other
    controllers.

    View full-size slide

  17. Problem: Adding to or
    modifying the monolithic
    application is time-
    intensive and affects
    everyone who works on
    the app.

    View full-size slide

  18. The Monolithic app
    End User
    Application
    Business Logic
    Database

    View full-size slide

  19. The Monolithic app
    End User
    Application
    Business Logic
    Database

    View full-size slide

  20. Service Oriented app
    End User
    Application
    Business Logic
    Database
    App
    Models
    Database
    App
    Models
    Database

    View full-size slide

  21. End User
    Application
    Business Logic
    Database
    App
    Models
    Database
    App
    Models
    Database
    Service Oriented app

    View full-size slide

  22. End User
    Application
    Business Logic
    Database
    App
    Models
    Database
    App
    Models
    Database
    Service Oriented app

    View full-size slide

  23. End User
    Application
    Business Logic
    Database
    App
    Models
    Database
    App
    Models
    Database
    Service Oriented app

    View full-size slide

  24. A monolithic application
    is a single codebase
    responsible for handling
    all application
    functionality.

    View full-size slide

  25. A service oriented
    application is composed
    of many codebases each
    doing one thing only.

    View full-size slide

  26. Do you even need a service
    oriented architecture?

    View full-size slide

  27. Benefits of SOA
    • Reduces complexity of logic by removing
    unnecessary dependencies.

    • Makes deployments of new features and changes
    independent.

    • Provides an easy way to divide work and parallelize.

    • Makes it substantially easier to mix technologies.

    • Gives you the freedom to easily scale specific parts
    of your application.

    View full-size slide

  28. drawbacks of SOA
    • Managing multiple codebases is hard.

    • More codebases means more dependencies.

    • Development environments are more complex.

    • Much more difficult to understand the system as a
    whole.

    View full-size slide

  29. When to use SOA
    • You have a huge, cumbersome codebase and team.

    • You have an API-driven product/business.

    • You need independent scalability.

    View full-size slide

  30. When NOT to use SOA
    • Almost every other time.

    View full-size slide

  31. What you need to SOA
    • Experienced developers capable of building out APIs
    and abstractions around APIs that may or may not
    exist yet.

    • Time.

    • The ability to reject feature requests while you
    develop a robust platform.

    View full-size slide

  32. Things You Don’t Have
    • Experienced developers capable of building out APIs
    and abstractions around APIs that may or may not
    exist yet.

    • Time.

    • The ability to reject feature requests while you
    develop a robust platform.

    View full-size slide

  33. How to introduce SOA into
    your monolith

    View full-size slide

  34. End User
    Application
    Business Logic
    Database
    App
    Models
    Database
    App
    Models
    Database
    Service Oriented app

    View full-size slide

  35. Application
    Business Logic
    Database
    App
    Models
    App
    Models
    Service Oriented app

    View full-size slide

  36. Architecture
    models
    controllers
    views
    libs
    services
    +

    View full-size slide

  37. Payments
    libs
    authorize.net

    View full-size slide

  38. Payments
    libs
    authorize.net
    Braintree

    View full-size slide

  39. Payments
    libs
    authorize.net
    Braintree
    App
    Models
    Database

    View full-size slide

  40. interface PaymentGateway
    {
    public function charge(Payment $payment);
    public function refund(Payment $payment);
    }

    View full-size slide

  41. interface PaymentGateway { }
    class AuthorizeGateway extends PaymentGateway
    {
    public function charge(Payment $payment)
    {
    $authorize = new AuthorizeNetAIM();
    /* some code omitted */
    return $authorize->authorizeAndCapture();
    }
    }

    View full-size slide

  42. interface PaymentGateway { }
    class AuthorizeGateway extends PaymentGateway { }
    class BraintreeGateway extends PaymentGateway
    {
    public function charge(Payment $payment)
    {
    return Braintree_Transaction::sale(array(
    'amount' => $payment->amount
    ));
    }
    }

    View full-size slide

  43. interface PaymentGateway { }
    class AuthorizeGateway extends PaymentGateway { }
    class BraintreeGateway extends PaymentGateway { }
    class PaymentGatewayFactory
    {
    public static function create($gatewayType)
    {
    switch ($gatewayType) {
    case 'Authorize':
    return new AuthorizeGateway(/*...*/);
    case 'Braintree':
    return new BraintreeGateway(/*..*/);
    case 'GiftCard':
    return new GiftCardGateway(/*..*/);
    default:
    throw new UnknownGatewayException($gatewayType);
    }
    }
    }

    View full-size slide

  44. Payments
    libs
    authorize.net
    Braintree
    App
    Models
    Database

    View full-size slide

  45. namespace PaymentService;
    class Client
    {
    public function purchase($payment, $options = array())
    {
    $requestBody = new ChargeRequest(
    $payment->amount,
    $payment->currency,
    true,
    $payment->card
    );
    $client = new \Guzzle\Http\Client();
    $post = $client->post(
    "",
    array('Content-Type' => 'application/json'),
    $requestBody->to_json()
    );
    $response = $post->send();
    return $this->decode_json($response->getBody());
    }
    }

    View full-size slide

  46. namespace PaymentService;
    class Client { }
    class PaymentServiceGateway
    {
    public function charge(Payment $payment)
    {
    $client = new \PaymentService\Client();
    return $client->purchase($payment);
    }
    }

    View full-size slide

  47. namespace PaymentService;
    class Client { }
    class PaymentServiceGateway { }
    class PaymentGatewayFactory
    {
    public static function create($gatewayType)
    {
    switch ($gatewayType) {
    case 'Authorize':
    case 'Braintree':
    case 'GiftCard':
    return new PaymentServiceGateway(/*..*/);
    default:
    throw new UnknownGatewayException($gatewayType);
    }
    }
    }

    View full-size slide

  48. What have we achieved?

    View full-size slide

  49. Architecture
    End User
    Application
    Business Logic
    Database

    View full-size slide

  50. Architecture
    End User
    Application
    Business Logic Database
    Services
    Business Logic

    View full-size slide

  51. libs
    authorize.net Braintree
    App
    Models
    Database service
    service
    service
    service
    JS App

    View full-size slide

  52. Recap
    • Much like the evolution of your understanding of
    architectures, the evolution of a monolithic
    application to a service-oriented architecture will
    not happen overnight.

    View full-size slide

  53. Recap
    • SOA is powerful and useful in certain situations.

    View full-size slide

  54. Recap
    • It is possible to build towards SOA without picking
    up as much of the complexity burden until you are
    forced to.

    View full-size slide

  55. JEFF CAROUTH
    Lead Platform Engineer at Liftopia
    Mid-level Tweeter as @jcarouth
    Inbox(0) guy at [email protected]
    Freenode user as jcarouth
    Co-Host of Loosely Coupled
    Founder of Dev Book Club

    View full-size slide

  56. Thank You
    @jcarouth
    joind.in/13568

    View full-size slide