Consumer-Driven Contracts

A Contract Vocabulary: Part 2

April 1st, 2008  |  Published in Consumer-Driven Contracts by Ian Robinson

In my last post I described Consumer-Driven Contracts as an attempt at a contract vocabulary with three core terms: provider contracts, consumer contracts and consumer-driven contracts. In this post I’ll flesh out each of those terms.

Provider Contracts

These are the contracts with which many of us imbued with service-oriented concepts will be most familiar. They’re the contracts identified in that hoary old tenet, “Services share schemas and contracts, not classes and types.” Provider contracts mark services as king of their own domain – “this is what I am, what I offer, take it or leave it.” They’re the first-line defence in the struggle to preserve service autonomy. As I suggested in my previous post, in the WS-* world provider contracts typically comprise some or all of WSDL plus XML Schema plus WS-Policy.

Consumer Contracts

These kinds of contract are really a private affair, particular to a specific consumer – to the way in which that consumer uses a service. In short, a consumer contract is a description of the parts of the service in which the consumer is really interested, the parts upon which it really depends. These might be interfaces, parts of an interface, operations, schemas, parts of schemas, quality-of-service characteristics, etc.: all those things I cheerfully labelled “a logical set of exportable business function elements.” More often than not, these specific usage characteristics remain implicit, and can be gleaned only be diving into the implementation of the consumer.

Some consumers need everything a provider exports: schemas, operations, endpoints, policies, and so on. More often than not, however, a consumer really only needs a subset of what the provider offers. Some consumers import only what is absolutely necessary, and ignore or tolerate changes in all the rest, but others will import or bind to everything, irrespective of its usefulness. Binding to everything might be appropriate in some circumstances, but at other times it’s a real barrier to evolution.

Oddly enough, I get the feeling that when people refer to consumer-driven contracts, they’re actually talking about consumer contracts. Most of the practical work in the area of service evolution seeks to reduce the amount of knowledge a consumer must have of a provider, whether it’s knowledge of a provider’s implementation (almost always a bad idea), or knowledge of parts of a provider contract that really have no bearing on the consumer. After all, knowledge is a dependency, isn’t it? Reduce the consumer’s knowledge of the provider – limit the scope of the consumer contract – and so achieve just enough coupling, no more.

I suggest it’s useful for consumers to know what their consumer contracts are.

Consumer-Driven Contracts

In the original article I also called these derived contracts, but I don’t often use that term: “consumer-driven contracts” was suggested to me by Robin Shorrock, and I much prefer it – though if you’ve been test-, behaviour-, budget- and whatnot- driven to a frenzy, you might prefer “derived.”

Consumer-driven contracts bring the contractual forces back home to the provider. Assume for a moment that you could identify all the current consumers of your service; assume also that for each consumer you could know its consumer contract. A consumer-driven contract is the aggregate of all these consumer contracts. It’s a snapshot of existing contractual relations: it’s what the provider has to do to really satisfy existing dependencies, as opposed to what it started off offering. On the one hand, the provider offers a provider contract – “all that I am” – on the other, based on some set of current consumer expectations, it’s obliged to maintain only some portion of this contract. (Note that in some cases this “some portion” might in fact be everything that a provider offers under its provider contract, in which case its provider and consumer-driven contract look similar.)

Whilst we can say that a weak form of consumer-driven contract is implicit in all provider-consumer relations, Consumer-Driven Contracts took the idea a little further, suggesting that consumers might wish to import their consumer contracts into the provider, thereby surfacing an explicit consumer-driven contract.

Now the thorny question is: should you really seek to identify a provider’s “real” contractual obligations? After all, isn’t this extra knowledge, and isn’t extra knowledge an extra dependency, a tightening of the coupling screw?

My first response is to point out that these consumer expectations, and the provider’s obligation to satisfy them, exist whether we like it or not. Change something upon which a consumer currently depends, and you might very well break that consumer. Wouldn’t it be useful to know what you can and can’t change about a provider’s exported functionality, its provider contract, based on a “current” view of consumer relations? Wouldn’t this perhaps help you plan and govern the evolution of your service in response to changing business requirements?

I suggest that in many cases it’s useful for a provider to know what its consumer-driven contract is.

Atom   RSS 2.0   Email

A Contract Vocabulary: Part 1

March 27th, 2008  |  Published in Consumer-Driven Contracts by Ian Robinson

Consumer-Driven Contracts was first and foremost an attempt at a contract vocabulary – though you’d be forgiven for thinking otherwise: the vocabulary definitions are buried away in a wealth of implementation detail. The original article is based around a simple, XML-based example – that of evolving an Order message schema in response to the changing needs of both a service provider and its consumers. On top of that, I discuss the Must Ignore convention as it is applied in XML Schema, and the use of languages such as Schematron to implement alternatives to XML Schema validation.

Looked at from the point of view of these details, the article appears to be nothing more that a summary of some reasonably well-known validation techniques as they apply to specific schema, validation and contract languages. But I’m not sure that’s all there is to it. For me, the core focus has always been on a simple separation of concerns. Consumer-Driven Contracts was motivated by a desire to unpack the term “loosely coupled;” to turn a spotlight on the several facets of the contractual relations between services, and to name each part. I wanted to create a vocabulary for describing the roles of the participants in a loosely coupled relationship, so that we might better understand who does what when a service changes, and so articulate the knotty problem of service evolution.

Services collaborate to satisfy a business process. Where two services communicate, at least one assumes the role of provider, the other of consumer. To the extent that the consumer uses something of the provider, it is coupled to that provider. In the interests of autonomy, process agility, reuse, and so on, we seek to reduce the degree of coupling between providers and consumers. But no matter how successful we are in loosely coupling services, we recognize that for a system to do something useful, some small amount of coupling must remain.

What does it mean to be coupled, one service to another? What relations or forces are at play between provider and consumer? Between a provider and all the consumers who depend upon it?

Service Contracts

We can begin answering these questions by reviewing our understanding of service contracts. Service contracts are often described as what the requestors and providers of a service must agree on. In the WS-* universe, service contracts are expressed using commoditised, standards-based XML vocabularies:

  • WSDL (Web Service Description Language) descriptions of a service’s operational behaviour – including structural definitions of the operations a service supports and the messages that go in and come out of a service – together with details of where to find a service and how to bind to it;
  • XML Schema descriptions of the messages sent and received by the service;
  • WS-Policy descriptions of any constraints on accessing and using the service, such as security requirements that a consumer must adhere to, or acceptable transports over which the service can be contacted. Policies separate these constraints from the service’s behaviour: if a service is relocated, perhaps to a new address or transport, its policy may change whilst its behaviour remains the same.

Such service contracts promote loose coupling by encapsulating the provider’s execution environment, thereby increasing the platform independence of the several parties in a distributed system.

A key point to note about Web Service contracts is that they are almost always explicit, being published using one or more of the contract formats described above. With the standardisation of these formats, there arose widespread tool support for generating language-specific clients and message representations. Looked at in one way, this appears to be the natural maturation of the Web Services platform; looked at another, the volume of tool support hints at the development burden imposed by a service’s relative freedom to implement an illimitable number of operations and message schemas. Operations proliferate because there are no intrinsic constraints on the number or names of operations exposed by a WS-* service: your service exposes a GetCustomerDetails operation; mine supports HandleCustomerDetailRequest. Message schemas proliferate in large part because of the de facto predominance of XML. If all you have is XML, then the choice – if you can call it a choice – of media type adds nothing to the interpretation of a message. This leads us to innovate at the level of the structure of the representations we make using that one media type: all too often, your Customer schema ends up looking nothing like my Customer schema.

In short, the Web Services platform trades standardised, commoditised and constrained contract metadata in return for an unconstrained set of operations and message schemas. From the point of view of a consumer wanting to invoke operations on and exchange messages with service providers, each service differs from every other, thereby requiring a service-specific proxy per consumer. Hence the need for explicit contracts on the provider side and toolset support for generating proxies on the consumer side.

Unlike WS-* services, RESTful services typically eschew explicit contracts: but that doesn’t mean that RESTful contracts don’t exist. Stefan Tilkov discusses this very issue in his Addressing Doubts about REST. The implicit RESTful contract is in large part captured by the HTTP specification, which describes a set of operations that can be performed on the resources exposed by a service, together with a set of response codes that guide a consumer’s interactions with those resources. Format-wise, REST encourages us to choose an appropriate IANA-recognised media type, such as XHTML, Atom, JSON, form encoding, or even XML, to structure a representation in the most economical and widely recognized manner possible. This focuses us on identifying potential structural similarities in our data, rather than essential semantic differences. A set of configuration parameters, for example, appears quite different from a customer’s contact details; leading us, perhaps, to create a Config schema for the one, a Customer schema for the other. But looked at in terms of their structure, both resources might be thought of as comprising sets of name-value pairs, making it practical to represent them in a widely recognised form-encoded format.

Whether implicit or explicit, service contracts to date have been overly provider-centric. In contrast to this monadic focus, Consumer-Driven Contracts distinguishes three types of contract: provider contracts, consumer contracts and consumer-driven contracts. I suggest that these contractual relations exist whether we like it or not. In a sense, we don’t opt to implement these contracts, least of all the consumer and consumer-driven contracts: they exist from the moment a service is up and running and being used by one or more clients. We’re not obliged to design and build to these contracts, but having named them and surfaced them as distinct from one another, we can leverage their characteristics if we so choose.

In my next post I’ll describe each of these three contracts in more detail.

Atom   RSS 2.0   Email

Consumer-Driven Contracts: A Retrospective

March 22nd, 2008  |  Published in Consumer-Driven Contracts by Ian Robinson

ThoughtWorks Anthology

A couple of years ago I wrote about some of the challenges we face when evolving services in response to changes in the business processes they implement, or to changes in the way they are used by their consumers. The resulting article, Consumer-Driven Contracts: A Service Evolution Pattern, was published on Martin Fowler’s site and shortly thereafter on MSDN. This month I’m delighted to announce that a newly revised version can be found – in somewhat humbling company – in the fabulous ThoughtWorks Anthology.

Consumer-Driven Contracts described what I perceived to be a common problem in real-world service-oriented solutions – that of the ostensibly loosely-coupled service estate being in fact extremely difficult to change on a service-by-service basis – and explained how we might make our service providers and consumers more independent of one another and better able to tolerate change. The article drew on my experience of building services in large organizations where, because of our schedule of frequent releases, we had to balance innovation with the minimum of system and organisational disruption. Besides discussing how we can engineer services that are tolerant of change, the article touched on several other topics related to the design and delivery of distributed systems – topics that interested me then, and continue to interest me today:

  • Are agile software methodologies compatible with delivering organizational agility in the context of a service-oriented approach to business process automation?
  • How can we align the specification and delivery of service functionality with the key business process drivers within an organisation?
  • What are the roles and responsibilities of the several parties in a loosely coupled relationship?
  • Under what circumstances can we depend on toolset-assisted service implementations, and when should we adopt more deliberate – sometimes more complex – implementation strategies, to ensure the longevity of a system?
  • How ought we to translate the collaborations between the business functions through which an organisation realizes its core processes into our services’ externally observed behaviours and interactions?

I’ve discussed the ideas in Consumer-Driven Contracts with many friends and colleagues over the last couple of years, and have learnt much by continuing to test and refine their application at ground level. Now with the recent publication of the ThoughtWorks Anthology, I thought it appropriate to conduct something of a retrospective. Beginning with my next post, where I’ll consider Consumer-Driven Contracts in terms of its describing a contract vocabulary, I’ll reflect on what I’ve learnt, unpick some of the several strands in the article, and dive further into some of its more important themes.

Updated: The first three parts of this retrospective can be found here:

Atom   RSS 2.0   Email