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

Contract-First Integration: Enabling Parallel S...

Contract-First Integration: Enabling Parallel Systems Development

Modern systems fail not because of code, but because of integration friction between teams.
This talk presents a Contract-First integration approach that transforms system integration from a serial, coordination-heavy process into a parallel, governed, and automated workflow.

You’ll learn how defining integration contracts before implementation enables teams to work independently while maintaining strong alignment through CI/CD enforcement.

The presentation covers real-world Java-based examples across REST APIs, Kafka events, and database schemas, showing how contracts become first-class artifacts that drive parallel development, safe evolution, and zero-surprise integrations.

What you’ll learn
• What Contract-First really means in practice (beyond theory)
• How contracts enable parallel development between providers and consumers
• REST contracts with OpenAPI and generated clients
• Event-driven contracts with Kafka, Avro, and Schema Registry
• Database contracts using Flyway migrations
• Schema evolution without downtime (Expand → Migrate → Contract)
• Enforcing contracts automatically in CI/CD
• Idempotency, retries, error models, and non-functional guarantees
• Migrating legacy systems safely using contracts as a bridge

Who this talk is for
• Backend engineers and senior developers
• Java & JVM engineers
• Software architects and tech leads
• Teams working with microservices or distributed systems
• Organizations struggling with cross-team integration delays

Key takeaway

Contract-First turns integration from a coordination problem into a governance problem — and automation solves governance.

Avatar for Wallace Espindola

Wallace Espindola

February 10, 2026
Tweet

More Decks by Wallace Espindola

Other Decks in Programming

Transcript

  1. What is Contract-First? Contract-First = Define the integration boundary FIRST,

    then implement code that conforms to it. A contract includes: • Operations (endpoints, topics) • Data shapes (request/response, events) • Validation rules • Error models • Security requirements • Non-functional rules (timeouts, retries, idempotency) • Versioning strategy Key Principle: The contract is the SINGLE SOURCE OF TRUTH
  2. The Problem: Traditional Integration System A ---- [waiting...] ----> System

    B ↓ Team A: "When will B be ready?" Team B: "We're still implementing..." ↓ Integration happens LATE Surprises emerge Assumptions drift Result: Serial dependency, delayed integration, late surprises
  3. The Solution: Contract-First 1. Agree on contract (API/event schemas) ↓

    2. Generate stubs/clients/mocks from contract ↓ 3.1 System A implements provider (parallel) 3.2 System B implements consumer (parallel) ↓ 4. CI enforces contract alignment Result: Parallel development, early validation, no surprises
  4. Three Contract Types in Java 1⃣ REST API Contract •

    Format: OpenAPI 3.0 YAML/JSON • Generates: Server stubs, DTOs, client SDKs, mock servers 2⃣ Kafka/Event Contract • Format: Avro/Protobuf schemas + AsyncAPI • Generates: Java classes, consumer fixtures 3⃣ Database Contract • Format: Flyway SQL migrations • Generates: Versioned, repeatable deployments
  5. REST Contract Example paths: /v1/orders: post: operationId: createOrder responses: '201':

    description: Created '400': description: Validation error '409': description: Idempotency conflict
  6. REST Implementation (Java/Spring) @RestController @RequestMapping("/v1/orders") public class OrdersController { @PostMapping

    public ResponseEntity<OrderResponse> create( @RequestBody CreateOrderRequest request) { OrderResponse created = service.createOrder(request); return ResponseEntity.status(201).body(created); } }
  7. Consumer Parallel Work System B doesn't wait for System A!

    ✅ Generate Java client from OpenAPI spec immediately ✅ Run mock server for development ✅ Build integration tests against mock ✅ Switch to real API when ready No runtime dependency on the provider being finished
  8. Kafka Contract: Topic Semantics # Topic: orders.order-created.v1 - Purpose: Emitted

    when order created - Key: orderId (ordering per order) - Delivery: at-least-once - Consumer: idempotent processing - Retry: consumer retries errors - DLQ: orders.order-created.v1.dlq - Compatibility: backward compatible
  9. Kafka Contract: Avro Schema { "type": "record", "name": "OrderCreated", "namespace":

    "com.acme.events", "fields": [ { "name": "eventId", "type": "string" }, { "name": "orderId", "type": "string" }, { "name": "customerId", "type": "string" }, { "name": "source", "type": ["null", "string"], "default": null } ] }
  10. Kafka Producer (Java) public class OrderEventPublisher { private final KafkaTemplate<String,

    OrderCreated> kafka; public void publishOrderCreated(OrderCreated event) { kafka.send( "orders.order-created.v1", event.getOrderId(), event ); } }
  11. Kafka Consumer with Idempotency @KafkaListener(topics = "orders.order-created.v1") public void onOrderCreated(OrderCreated

    event) { // Check if already processed if (processedEventsRepo.existsByEventId( event.getEventId())) { return; // skip duplicate } // Process event billingService.createInvoice(...); // Store eventId processedEventsRepo.save(event.getEventId()); }
  12. Database Contract: Flyway Migration CREATE TABLE orders ( id VARCHAR(32)

    PRIMARY KEY, customer_id VARCHAR(32) NOT NULL, status VARCHAR(16) NOT NULL, created_at TIMESTAMP NOT NULL ); CREATE TABLE order_items ( order_id VARCHAR(32) REFERENCES orders(id), sku VARCHAR(64) NOT NULL, quantity INT NOT NULL, PRIMARY KEY (order_id, sku) );
  13. Schema Evolution: Expand/Migrate/Contract -- V2__add_order_source.sql (Expand) ALTER TABLE orders ADD

    COLUMN source VARCHAR(32); -- Backfill (Migrate) UPDATE orders SET source = 'UNKNOWN' WHERE source IS NULL; -- Enforce (Contract) ALTER TABLE orders ALTER COLUMN source SET NOT NULL;
  14. End-to-End Flow 1. REST API Request ↓ (OpenAPI validation) 2.

    Persist to Database ↓ (Flyway schema) 3. Publish Kafka Event ↓ (Avro schema + Schema Registry) 4. Consumers Process Event (with idempotency) Three contracts working together
  15. Service Implementation @Transactional public OrderResponse createOrder(CreateOrderRequest req) { // 1.

    Persist (DB contract) ordersRepository.save(...); orderItemsRepository.saveAll(...); // 2. Publish event (Kafka contract) OrderCreated event = OrderCreated.newBuilder() .setEventId(UUID.randomUUID().toString()) .setOrderId(orderId) .build(); publisher.publishOrderCreated(event); // 3. Return (REST contract) return new OrderResponse(...); }
  16. Parallel Development Scenarios 🔹 REST Integration Provider builds server, Consumer

    builds client using SDK No blocking - both work independently 🔹 Event-Driven Integration Publisher and consumer build against same Avro schema No runtime dependency on each other 🔹 Legacy ↔ New System Legacy exposes contract, New system builds against it Contract serves as the "bridge"
  17. CI/CD Gates: Making Contracts Real 🛡 REST: OpenAPI Breaking Change

    Detection Run OpenAPI diff tool in CI 🛡 Kafka: Schema Compatibility Check Enforce backward compatibility in Schema Registry 🛡 DB: Migration Validation Flyway validates migrations 🛡 Consumer-Driven Contract Tests Tools like Pact validate expectations
  18. Practical Rules in Contracts Versioning • REST: /v1, /v2 or

    semantic versioning • Kafka: compatibility policy + versioned topics Errors & Retries • REST: standardized ErrorResponse • Kafka: retry policy + DLQ envelope Idempotency • REST: Idempotency-Key header • Kafka: eventId + consumer dedupe
  19. Mental Model Shift Without Contract-First ❌ Serial dependency ❌ Teams

    block each other ❌ Late integration surprises With Contract-First ✅ Parallel development ✅ Early validation ✅ No surprises ✅ CI enforces alignment
  20. From Coordination to Governance Traditional: Coordination Problem • Team A

    waits for Team B • Manual coordination • High coupling Contract-First: Governance Problem • Teams agree on contract upfront • Generate tools automatically • CI enforces compliance • Low coupling, high autonomy
  21. Benefits Summary ✅ Enables Parallel Development Teams no longer block

    each other ✅ Reduces Integration Risk Contracts catch breaking changes early ✅ Improves Evolution Versioning is explicit ✅ Essential for Microservices Clear boundaries enable scaling
  22. Real-World Impact Before Contract-First: 🕐 Integration: 2-3 weeks waiting +

    1 week debugging 🐛 Breaking changes in production 👥 Constant coordination After Contract-First: 🕐 Integration: 1 day + parallel work 🐛 Breaking changes caught in CI 👥 Independent work Result: 10x faster, zero surprises
  23. Getting Started 1. Choose a contract type (REST, Kafka, or

    DB) 2. Define the contract first (before any code) 3. Generate tools (stubs, clients, classes) 4. Build independently 5. Add CI gates 6. Evolve safely (versioning + compatibility)
  24. Tools & Technologies REST Contracts • OpenAPI 3.0, openapi-generator, Swagger

    UI, Prism Kafka Contracts • Apache Avro, Confluent Schema Registry, AsyncAPI Database Contracts • Flyway, Liquibase, Version control
  25. Best Practices ✅ DO: • Version all contracts explicitly •

    Generate code from contracts • Enforce compatibility in CI • Test contract compliance ❌ DON'T: • Hand-write DTOs (generate them!) • Skip schema validation • Make breaking changes without version bump
  26. Common Pitfalls ❌ "We'll add the contract later" Wrong: Contract

    MUST come first ❌ "Just make a quick change" Wrong: All changes go through contract + CI ❌ "Our team doesn't need contracts" Wrong: Even single-team projects benefit ❌ "Contracts slow us down" Wrong: Contracts enable speed through parallelism
  27. Advanced Patterns Idempotency Strategies • REST: Idempotency-Key header + request

    hash • Kafka: eventId + processed events table Schema Evolution • Add fields with defaults (backward compatible) • Expand → Migrate → Contract pattern Dead Letter Queues • Envelope schema for DLQ messages • Error classification (retriable vs non-retriable)
  28. Case Study: Order System Contracts: • REST: orders-api.v1.yaml (create, get

    orders) • Kafka: OrderCreated.v1.avsc (event) • DB: V1__create_orders.sql (schema) Teams: • Orders Team: REST API + publisher • Billing Team: Kafka consumer • Fulfillment Team: Kafka consumer Result: All teams work in parallel from day 1
  29. Integration with CI/CD # GitHub Actions name: Contract Validation jobs:

    openapi-check: - run: npx openapi-diff \ main/orders-api.v1.yaml \ ${{ github.ref }}/orders-api.v1.yaml schema-compatibility: - run: mvn schema-registry:test-compatibility
  30. Monitoring & Observability Track Contract Compliance: • Schema Registry compatibility

    violations • OpenAPI spec violations • Failed Flyway migrations Metrics to Monitor: • Contract update frequency • Breaking change attempts blocked • Consumer lag (Kafka) • API error rates
  31. Migration Strategy Phase 1: Adopt for New Features Start with

    new APIs/events only Phase 2: Retrofit Critical Paths Add contracts to high-traffic integrations Phase 3: Mandate for All Make contract-first mandatory Phase 4: Automate Governance CI/CD enforces compliance Tip: Start small, prove value, expand
  32. Team Organization Architecture Team ↓ Defines contract standards Provider Team

    | Consumer Team 1 | Consumer Team 2 ↓ CI enforces contracts Clear separation of concerns Automated enforcement Independent deployment
  33. Resources Documentation • OpenAPI Specification: openapis.org • AsyncAPI: asyncapi.com •

    Apache Avro: avro.apache.org Tools • openapi-generator.tech • Postman / Insomnia • Schema Registry Books • "Building Microservices" - Sam Newman • "Release It!" - Michael Nygard
  34. Key Takeaways 1⃣ Contract-First = Parallel Development 2⃣ Three Contract

    Types: REST, Kafka, DB 3⃣ CI Enforces Alignment 4⃣ Evolution is Built-In 5⃣ From Coordination to Governance
  35. Call to Action 🚀 Start Today: 1. Pick one integration

    to convert 2. Write the contract FIRST 3. Generate tools from contract 4. Add CI validation 5. Measure the impact 📚 Learn More: github.com/wallaceespindola/contract-first-integrations
  36. Questions? Wallace Espindola Sr. Software Engineer / Solution Architect 📧

    [email protected] 🔗 linkedin.com/in/wallaceespindola 💻 github.com/wallaceespindola Code: github.com/wallaceespindola/contract-first-integrations Presentation: speakerdeck.com/wallacese Thank you! 🙏