enterprise REST a case study twitter:@BrandonByars �
the eight fallacies of distributed programming • the network is reliable • topology doesn’t change • latency is zero • there is one administrator • bandwidth is infinite • transport cost is zero • the network is secure • the network is homogenous
Forcing people to use HATEOA your links � S Standard HTTP Interface � URI Resources � POX RPC / SOAP �
HATEOA S Most REST mistakes HTTP happen over here… � versioning URI deployment testing POX service granularity
REST
a story about a billing system...
a story about a legacy rewrite...
dramatis personae
field ¡force ¡ inventory: ¡ CSR ¡ management ¡ telephony ¡ UI ¡ order ¡ management ¡ order ¡ provisioning ¡ dramatis entry ¡ personae product ¡ inventory: ¡ catalog ¡ physical ¡ customer ¡ billing ¡ Web ¡ address ¡
Choreography... ...not orchestration
define logical environments for isolation
Shared Integration VM � Bob’s Workstation � Order � C1 � Customer � O1 � Mary’s Workstation � P1 � Product � Order � O1 �
Shared Integration VM � Bob’s Workstation � P1 � Product � Order � C1 � Customer � O1 � Mary’s Workstation � P2 � Product � Order � C2 � Customer � O1 �
Shared Integration VM � Bob’s Workstation � P1 � Product � Order � C1 � Customer � O1 � Mary’s Workstation � P2 � Product � Order � C2 � Customer � O1 �
Bob’s Environment � Shared Integration VM � Bob’s Workstation � P1 � Product � Order � C1 � Customer � O1 � Mary’s Workstation � P2 � Product � Order � C2 � Customer � O1 � Mary’s Environment �
coordinated deployments
order-bob: � product: � webServers: [s1.test.dev] �� url: http://s1.test.dev: 8000 /products � dbServer: s1.test.dev � dbName: OrderBobProducts � customer: � webServers: [s1.test.dev] � url: http://s1.test.dev: 8001 /customers � dbServer: s1.test.dev � dbName: OrderBobCustomers � � order-mary: � product: � webServers: [s1.test.dev] � url: http://s1.test.dev: 8002 /products �
order-bob: � product: � webServers: [s1.test.dev] �� url: http://s1.test.dev: 8000 /products � dbServer: s1.test.dev � dbName: OrderBobProducts � customer: � webServers: [s1.test.dev] � url: http://s1.test.dev: 8001 /customers � dbServer: s1.test.dev � dbName: OrderBobCustomers � � order-mary: � product: � webServers: [s1.test.dev] � url: http://s1.test.dev: 8002 /products �
version as a last resort
UI � 4.1.1 � Order Billing � Entry � 5.13.3 � Product �
speling mistaeks { � { � "customer": { � "customer": { � "firstName": "Fred", � "firstName": "Fred", � "LastName": "Flinstone" � " lastName ": "Flinstone" � } � } � } � } �
Postel’s Law @RequestMapping(method=POST, produces=application/json) � @ResponseBody � public OrderResource createOrder( � � @RequestBody Order order, � � HttpServletResponse response � ) throws OrderException � { � � ... � � ... � } �
separate functional testing from integration testing
deployment pipeline Commit � Automated � Showcase � SIT � Pre-prod � Production � Tests � 3.1.12 � 3.1.11 � 3.1.3 � 3.0.6 � 3.0.6 � 2.16.1 �
deployment pipelines... Isolated SIT � Pre-prod � Production � Pipelines � 3.1.3 � 3.0.6 � 3.0.6 � 2.16.1 � Order Entry � 4.2.3 � 4.2.0 � 4.1.2 � 4.1.1 � Billing � 7.2.6 � Product � 7.2.0 � 7.2.0 � 7.2.0 � 2.2.5 � 2.2.0 � UI � 2.2.0 � 2.1.33 �
early stages Commit � Isolation … � … � … � … � Tests � 3.1.12 � 3.1.11 � 3.1.3 � 3.0.6 � 3.0.6 � 2.16.1 � stub ruthlessly
hand-crafted stubs System Stub Under Server � Test � Tests �
record and replay stubs System Stub Real � Under Server � Dependency � Test � Tests �
general purpose stubs System Stub Under Server � Test � Stub � Setup � Tests �
Moco : https://github.com/dreamhead/moco � vcr : https://github.com/vcr/vcr � � β etamax : https://github.com/robfletcher/betamax � � stubby4j : https://github.com/azagniotov/stubby4j � � � mountebank : http://www.mbtest.org/ �
early stages Commit � Isolation … � … � … � … � Tests � 3.1.12 � 3.1.11 � 3.1.3 � 3.0.6 � 3.0.6 � 2.16.1 �
early stages Contract Commit � Isolation … � … � … � … � Tests � Tests � 3.1.12 � 3.1.11 � 3.1.3 � 3.0.6 � 3.0.6 � 2.16.1 �
Isolated Contract � Pre-prod � Production � Pipelines � Tests � 3.1.3 � 3.0.6 � 3.0.6 � 2.16.1 � Order Entry � 4.2.3 � 4.2.0 � 4.1.2 � 4.1.1 � Billing � 7.2.6 � Product � 7.2.0 � 7.2.0 � 7.2.0 � 2.2.5 � 2.2.0 � 2.2.0 � UI � 2.1.33 �
Isolated Contract � Artifacts � Pipelines � Tests � 3.1.3 � 3.1.2 � Order Entry � Tests � 4.2.3 � Billing � Tests � 7.2.6 � Product � 2.2.5 � UI � Tests �
Isolated Contract � Artifacts � Pipelines � Tests � 3.1.3 � 3.1.3 � Order Entry � Tests � 4.2.3 � Billing � Tests � 7.2.6 � Product � 2.2.5 � UI � Tests �
UI � 4.2.3 � Order Billing � Entry � 7.2.6 � Product �
Isolated Contract � Artifacts � Pipelines � Tests � 3.1.3 � Order Entry � Tests � 4.2.3 � Order Billing � Entry-3.1.3 � Tests � Billing-4.2.3 � Product-7.2.6 � 7.2.6 � Product � UI-2.2.5 � 2.2.5 � UI � Tests �
Isolated Contract � Artifacts � Pipelines � Tests � 3.1.3 � Order Entry � Tests � 4.2.3 � Billing � Tests � 7.2.6 � Product � 2.2.5 � UI � Tests �
[Test] ¡ public ¡void ¡ValidateProductAttributes() ¡ { ¡ ¡ ¡ ¡ ¡var ¡url ¡= ¡UrlForTestProduct(); ¡ ¡ ¡ ¡ ¡var ¡response ¡= ¡new ¡HttpResource(url) ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡.ThatAccepts("application/xml") ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡ ¡.Get(); ¡ ¡ ¡ ¡ ¡ ¡Assert.That(response.StatusCode, ¡Is.EqualTo(200)); ¡ ¡ ¡ ¡ ¡AssertHasXPath(response.Body, ¡"//productCode"); ¡ ¡ ¡ ¡ ¡AssertHasXPath(response.Body, ¡"//description"); ¡ ¡ ¡ ¡ ¡AssertHasXPath(response.Body, ¡"//monthlyCharge"); ¡ ¡ ¡ ¡ ¡AssertNumeric(ValueFor(response.Body, ¡"//monthlyCharge")); ¡ } ¡
use bounded contexts to control complexity
Rates � CSR UI � Product � Finance � Provisioning � Catalog � Invoicing � Billing � Marketing / � Website �
data rationalization
Conway’s Law Organizations which design In every organization there will systems ... are constrained to always be one person who knows produce designs what is going on. This person must which are copies of the be fired. communication structures of these organizations
augment � finance � record event � augment � get events � create � billing � product � augment � invoice �
twitter:@BrandonByars � http://martinfowler.com/articles/enterpriseREST.html �
Recommend
More recommend