📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

📚 Interview question

How do you write a contract for an asynchronous message, such as an OrderPlaced event on Azure Service Bus?

Senior Coding Advanced

🎯 Key points

  • Pact message interactions for async contracts; the pact is an executable schema of consumed fields
  • Consumer feeds the expected message to its real handler
  • Provider builds the message with its real serialisation code
  • Transport excluded; contract is body plus metadata (type, version)
  • Additive changes are safe; breaking changes go out as a new type or version alongside the old
  • Retries and dead-letter handling belong in consumer component tests, not the contract

⏱ 30-second answer

Use a Pact message (asynchronous) interaction. The consumer test describes the message it expects, with matchers for types and formats, and feeds it to its real handler, which must process it without error; that generates the pact, which acts as an executable schema for the fields the consumer relies on. The provider verification calls a message producer hook that builds the real message with the same serialiser and mapping code used in production, and checks it against the pact. The transport (Service Bus) is not part of the contract; the body and metadata (such as a type or version property) are. For evolution, add fields freely (consumers ignore unknown fields), never rename or remove a field a pact still uses, and introduce breaking changes as a new message type or version that runs alongside the old one until can-i-deploy shows no consumer needs it. Retries and dead-lettering are consumer behaviour, tested in the consumer's component tests, not in the contract.

🔍 What the interviewer is checking

Checks they can extend contract testing beyond HTTP to the integrations that usually break silently.

↩ Usually asked after

More in Senior Testing Topics

Last updated 23 Nov 2026.

🌐 Sangam's Webring

⏪ Previous 🏠 Main Next ⏩
💬 Chat with me