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. Agenda • What problem are we solving? • Why do

    I need an SOA? • How can I implement this in my existing ball of mud architecture?
  2. Problem: Adding to or modifying the monolithic application is time-

    intensive and affects everyone who works on the app.
  3. 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.
  4. 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.
  5. When to use SOA • You have a huge, cumbersome

    codebase and team. • You have an API-driven product/business. • You need independent scalability.
  6. 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.
  7. 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.
  8. interface PaymentGateway { } class AuthorizeGateway extends PaymentGateway { public

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

    class BraintreeGateway extends PaymentGateway { public function charge(Payment $payment) { return Braintree_Transaction::sale(array( 'amount' => $payment->amount )); } }
  10. 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); } } }
  11. 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()); } }
  12. namespace PaymentService; class Client { } class PaymentServiceGateway { public

    function charge(Payment $payment) { $client = new \PaymentService\Client(); return $client->purchase($payment); } }
  13. 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); } } }
  14. 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.
  15. Recap • It is possible to build towards SOA without

    picking up as much of the complexity burden until you are forced to.
  16. 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