API Design Patterns & Best Practices
API Design Patterns & Best Practices
Understanding individual TMF APIs is necessary but not sufficient. The real challenge lies in how these APIs are composed, integrated, and operated at scale. This section covers the architectural patterns that make TMF Open API ecosystems work in practice -- event-driven architecture, notification patterns, channel integration, versioning, and the most common anti-patterns to avoid.
These patterns are not specific to any single API. They apply across the entire TMF API landscape and represent hard-won lessons from real telco integration programmes.
The APIs themselves are the easy part. The patterns you use to connect them determine whether your architecture scales or collapses.
Event-Driven Architecture with TMF APIs
TM Forum Open APIs are designed for event-driven integration, not synchronous request/response chains. Every TMF API defines a set of events (create, state change, attribute change, delete) and a standard mechanism for delivering those events to interested subscribers.
TMF Event Types
Every TMF API defines a consistent set of event types for each managed resource. The pattern is predictable across all APIs:
Standard TMF Event Types
| Event Pattern | Trigger | Example (TMF622) |
|---|---|---|
| {Resource}CreateEvent | A new resource is created | ProductOrderCreateEvent |
| {Resource}StateChangeEvent | The lifecycle state changes | ProductOrderStateChangeEvent |
| {Resource}AttributeValueChangeEvent | A non-state attribute is modified | ProductOrderAttributeValueChangeEvent |
| {Resource}DeleteEvent | A resource is deleted | ProductOrderDeleteEvent |
| {Resource}InformationRequiredEvent | Additional information is needed (some APIs) | ProductOrderInformationRequiredEvent |
Each event contains the event metadata (eventId, eventTime, eventType) and the event payload -- a snapshot of the resource at the time of the event. This allows consumers to process the event without needing to call back to the source API.
The Hub/Listener Notification Pattern
The TMF Hub/Listener pattern is the standard mechanism for event delivery. It works like a publish-subscribe system where consumers register their interest and receive callbacks when events occur.
TMF Hub/Listener event notification pattern -- producers publish events, consumers receive callbacks
How It Works
Hub/Listener Registration and Notification
Register Listener
Consumer -> Producer HubConsumer calls POST /hub on the producer API with a callback URL and query filter specifying which events to receive. Example: POST /hub with body { "callback": "https://som.example.com/listener", "query": "eventType=ProductOrderStateChangeEvent" }.
Hub Stores Registration
Producer HubThe producer's hub stores the listener registration, including the callback URL and event filter. Multiple consumers can register independently.
Event Occurs
Producer SystemSomething changes in the producer system (e.g., a product order state transitions from InProgress to Completed).
Hub Matches Listeners
Producer HubThe hub evaluates the event against all registered listener filters and identifies matching subscriptions.
Callback Delivered
Producer Hub -> Consumer ListenerThe hub sends an HTTP POST to each matching listener's callback URL with the event payload. The listener processes the event asynchronously.
Polling vs Push Patterns
While the hub/listener pattern provides push-based notifications, some scenarios still warrant polling. Understanding when to use each pattern is important for building efficient integrations.
Polling vs Push (Hub/Listener)
| Aspect | Polling | Push (Hub/Listener) |
|---|---|---|
| How it works | Consumer periodically calls GET with filters | Producer pushes events to registered callbacks |
| Latency | Depends on polling interval (seconds to minutes) | Near real-time (milliseconds to seconds) |
| Network load | Constant, regardless of changes (wasteful when idle) | Proportional to actual changes (efficient) |
| Complexity | Simple to implement (just GET requests) | Requires listener endpoint, registration, error handling |
| Reliability | Consumer controls timing; missed polls can be caught up | Requires retry logic, dead-letter handling for failed deliveries |
| Coupling | Low -- consumer decides when to check | Medium -- consumer must expose a reachable endpoint |
| Best for | Batch processing, reporting, low-frequency checks | Real-time integration, order tracking, event chains |
Use push (hub/listener) for: order state tracking, real-time inventory updates, alarm notifications, SLA violation alerts. Use polling for: nightly reporting, batch data synchronisation, systems that cannot expose callback endpoints (e.g., behind strict firewalls).
In practice, most telco architectures use a hybrid approach:
- Hub/listener for real-time operational flows (order processing, alarm handling)
- Polling for batch/reporting flows (daily inventory snapshots, monthly SLA reports)
- A message broker (Kafka, RabbitMQ) as an intermediary that receives hub events and fans out to multiple consumers
- Change Data Capture (CDC) for database-level synchronisation where APIs are not available
Many modern telco platforms replace direct hub/listener callbacks with an event streaming platform like Apache Kafka. The TMF API producer publishes events to Kafka topics instead of (or in addition to) calling listener URLs directly. This provides:
- Durability -- events are persisted and can be replayed
- Decoupling -- producers and consumers do not need to know about each other
- Scalability -- consumers can be scaled independently via consumer groups
- Replay -- new consumers can process historical events from the beginning
- Ordering -- events for the same entity are delivered in order (within a partition)
The TMF event payload format remains the same; only the delivery mechanism changes from HTTP callback to Kafka topic.
Backend for Frontend (BFF) Pattern
TMF Open APIs are designed for system-to-system communication. They are not optimised for direct consumption by frontend applications (web, mobile, agent desktops). This is where the Backend for Frontend (BFF) pattern comes in.
Why Not Call TMF APIs Directly from the Frontend?
TMF APIs are granular, resource-oriented APIs designed for system integration. A single customer view screen might require data from TMF632 (Party), TMF637 (Product Inventory), TMF621 (Trouble Tickets), and TMF622 (Orders). Making 4+ API calls from the frontend is slow and creates tight coupling.
BFF Architecture
A Web BFF serves the browser-based customer portal or online shop. It provides:
- Product browsing endpoint that aggregates TMF620 (catalog) with TMF637 (current products) to show "available for you" offerings
- Customer dashboard endpoint that combines TMF632 (party), TMF637 (products), and TMF621 (open tickets) into a single response
- Order submission endpoint that validates, enriches, and submits to TMF622
- GraphQL or REST API optimised for web rendering patterns
API Versioning and Backward Compatibility
API versioning is a critical concern in telco environments where multiple systems evolve at different paces. TMF APIs follow semantic versioning (major.minor.patch) with specific compatibility rules.
TMF API Versioning Rules
| Version Change | Compatibility | Examples |
|---|---|---|
| Patch (4.0.0 -> 4.0.1) | Fully backward compatible (bug fixes only) | Fix typo in description, clarify documentation |
| Minor (4.0.0 -> 4.1.0) | Backward compatible (additive changes only) | Add new optional attribute, add new endpoint, add new event type |
| Major (3.x -> 4.0.0) | Potentially breaking changes | Remove attributes, change data types, restructure resources |
Versioning Strategies
TMF APIs include the major version in the URL path: /tmf-api/productCatalogManagement/v4/productOffering. When a major version changes, a new path is available alongside the old one, allowing consumers to migrate at their own pace.
In a real telco environment, you often need to support multiple API versions simultaneously. Strategies include:
- Parallel deployment -- run both v3 and v4 endpoints, with a shared backend
- API Gateway routing -- the gateway routes requests to the appropriate version based on the URL path
- Version translation -- a mediation layer converts v3 requests to v4 internally
- Sunset policy -- define clear timelines for deprecating old versions (e.g., 12 months after new version launch)
To ensure backward compatibility, implement consumer-driven contract testing. Each API consumer defines a contract specifying the fields, types, and behaviours it depends on. When the provider makes changes, these contracts are validated automatically:
- Use tools like Pact or Spring Cloud Contract to define consumer contracts
- Run contract tests as part of the provider's CI/CD pipeline
- Any change that breaks a consumer contract is flagged before deployment
- This catches breaking changes that version numbers alone might miss (e.g., changing the semantic meaning of a field)
API Gateway Patterns
An API Gateway is a critical infrastructure component in TMF API architectures. It sits between consumers and providers, handling cross-cutting concerns that would otherwise be duplicated in every API implementation.
- Authentication and Authorisation -- validate API keys, OAuth tokens, and enforce access policies
- Rate Limiting -- prevent any single consumer from overwhelming an API
- Request Routing -- direct requests to the appropriate backend service or version
- Protocol Translation -- convert between external protocols (HTTPS) and internal ones (gRPC, messaging)
- Request/Response Transformation -- modify payloads for version compatibility or data enrichment
- Monitoring and Analytics -- track API usage, latency, error rates, and generate reports
- Circuit Breaking -- prevent cascading failures when backend services are down
Common API Anti-Patterns
After years of TMF API adoption across the industry, several common anti-patterns have emerged. Recognising and avoiding these saves significant rework.
Anti-Pattern 1: The Chatty Integration
Anti-Pattern 2: Ignoring Events
Anti-Pattern 3: Tight Coupling via Shared Data
Anti-Pattern 4: Over-Engineering the Event Model
Anti-Pattern 5: No Idempotency
Anti-Pattern 6: Vendor-Specific API Extensions Everywhere
API Security Patterns
TMF APIs carry sensitive telco data (customer information, network topology, service configurations). Security is non-negotiable.
API Security Layers
| Layer | Mechanism | Purpose |
|---|---|---|
| Transport | TLS 1.2+ (HTTPS) | Encrypt data in transit |
| Authentication | OAuth 2.0, API Keys, mTLS | Verify caller identity |
| Authorisation | Role-based access control (RBAC), scopes | Control what each caller can access |
| Input Validation | Schema validation, input sanitisation | Prevent injection attacks and malformed data |
| Rate Limiting | Token bucket, sliding window | Prevent abuse and ensure fair usage |
| Audit Logging | Structured API access logs | Track who accessed what and when |
TM Forum Security Function (TMF630)
TMF630 provides guidelines and patterns for securing Open APIs, including OAuth 2.0 flows, token management, and consent handling. It is the foundation for securing any TMF API deployment.
API Testing Patterns
Testing TMF API integrations requires a layered approach that covers conformance, contracts, integration, and end-to-end scenarios.
API Testing Layers
| Test Type | What It Validates | Tools / Approach |
|---|---|---|
| Conformance Testing | API implementation matches the TMF specification | TMF Conformance Test Kit (CTK) |
| Contract Testing | API changes do not break existing consumers | Pact, Spring Cloud Contract |
| Integration Testing | Two systems communicate correctly via the API | Postman, REST Assured, custom test suites |
| End-to-End Testing | Full business flow works across all APIs | Cucumber/BDD scenarios covering Lead-to-Cash, Trouble-to-Resolve |
| Performance Testing | APIs meet latency and throughput requirements | JMeter, Gatling, k6 |
| Chaos Testing | System handles failures gracefully (timeouts, errors) | Chaos Monkey, Gremlin, custom fault injection |
API Observability
In a distributed TMF API architecture, observability is essential for understanding system behaviour, diagnosing issues, and ensuring service quality.
- Distributed Tracing -- trace a single order request across TMF622 -> TMF641 -> TMF652 -> TMF640 to identify bottlenecks and failures (use OpenTelemetry or Jaeger)
- Structured Logging -- correlate log entries across systems using a shared correlation ID passed as an HTTP header
- Metrics -- track API latency (p50, p95, p99), error rates, and throughput per endpoint
- Alerting -- set thresholds on key metrics (e.g., TMF622 error rate > 5% triggers PagerDuty alert)
- API Dashboards -- visualise API health across the entire TMF API landscape in real-time
Pattern Summary
When to Use Which Pattern
| Pattern | Use When | Avoid When |
|---|---|---|
| Hub/Listener | Real-time event notification between systems | Batch processing, systems behind strict firewalls |
| Polling | Batch reports, low-frequency checks, firewall-restricted consumers | Real-time operational flows |
| BFF | Frontend applications need aggregated, shaped API data | System-to-system integration (use TMF APIs directly) |
| API Gateway | Cross-cutting concerns (auth, rate limiting, routing) | Simple point-to-point integrations in development |
| Event Streaming (Kafka) | High-volume events, replay requirements, multiple consumers | Simple integrations with 1-2 consumers |
| Contract Testing | Multiple teams independently developing consumers and providers | Single-team environments with full control |
Section 5.6 Key Takeaways
- TMF APIs are designed for event-driven integration, not synchronous request/response chains
- The Hub/Listener pattern is the standard TMF mechanism for push notifications
- Use BFF (Backend for Frontend) layers to serve channel-specific frontends -- never expose raw TMF APIs to end users
- API versioning follows semantic versioning; run multiple versions in parallel during migration
- Avoid the six common anti-patterns: chatty integration, ignoring events, shared databases, over-engineered events, no idempotency, excessive vendor extensions
- API gateways handle cross-cutting concerns: auth, rate limiting, routing, monitoring
- Observability (tracing, logging, metrics) is essential for operating distributed TMF API architectures
- Use correlation IDs across the entire order chain for end-to-end traceability
- Security is non-negotiable: TLS, OAuth 2.0, RBAC, input validation, and audit logging are baseline requirements