# Behavior extensibility
## Asynchronous vs synchronous behavior
commercetools allows you to extend the behavior of its APIs with your business logic. In other words, you can customize how an API behaves. You can extend an API behavior using synchronous or asynchronous methods.
In synchronous behavior, the caller of the API has to wait for an answer. This often means that the end user of your application is waiting until a certain decision or action is taken by the application. In an asynchronous system, the application is aware that some action needs to be taken, but it can execute it in a non-blocking way.
Choosing whether to use a synchronous or asynchronous approach depends on your use case. For example, sending order confirmation emails using a synchronous system would cause your users an unnecessary wait time. This can be avoided by having an asynchronous process in place.
A synchronous approach is suitable for when you want to intercept a process and change its outcome dependent on certain conditions. A clear example of synchronous behavior is validating the contents of a cart. Imagine you have a business requirement where a customer cannot buy more than 6 tickets to a single concert. You can set up an application that checks this requirement. This application can be triggered by [Order-creation](/search.md?urn=ctp:api:endpoint:/{projectKey}/orders:POST) in commercetools. Before an Order is saved, the application can validate the contents of the [Cart](/search.md?urn=ctp:api:type:Cart) and decide whether to proceed with the Order or not.
You can customize the behavior of Composable Commerce APIs using:
- [Subscriptions](/api/projects/subscriptions.md) for asynchronous behavior.
- [API Extensions](/api/projects/api-extensions.md) for synchronous behavior.
## Subscriptions
Subscriptions are used to trigger an asynchronous background process in response to an event in commercetools. Common use cases include sending an order confirmation email, charging a credit card after a delivery has been made, or synchronizing customer accounts to a customer relationship management (CRM) system.
As you can see from the sequence diagram below, commercetools sends a notification after the Cart has been updated.
```mermaid
sequenceDiagram
participant A as Frontend application
participant B as commercetools
participant C as Messaging queue
A->>B: Add LineItem
(request)
B-->>B: Cart updated
B-->>B: Cart stored
B->>A: Updated Cart
(response)
note right of C: Messaging services supported:
AWS SNS, AWS SQS, and AWS EventBridge
---
Confluent Cloud
---
Google Cloud Pub/Sub
---
Azure Service Bus
Azure Event Grid
B->>C: New event
```
## API Extensions
An API Extension gets called after the processing of a create or update request of an API call, but before the result is persisted. The API Extension can validate the object in the request, or apply additional updates to it.
In the sequence diagram below, you can see that a response from the API Extension is required before commercetools can update the Cart (reference point 6).
```mermaid
sequenceDiagram
participant A as Frontend application
participant B as commercetools
participant C as Your service
A->>B: Add LineItem
(request)
B-->>B: Cart updated
alt proceed
B->>C: Is it okay?
C->>B: Yes
B-->>B: Cart stored
B->>A: Updated Cart
(response)
else block
B->>C: Is it okay?
C->>B: No
B-->>B: Cart rejected
note right of C: Hosted and managed outside of commercetools.
For example, as a serverless function.
B->>A: Rejected Cart
(response)
end
```
Your use case will likely determine which extensibility option fits best. However, using Subscriptions over API Extensions whenever possible, will lead to better overall performance.
Learn more about how to implement API Extensions and Subscriptions in our self-paced [Integration patterns with commercetools](/learning-integrate-with-commercetools/integration-patterns/overview.md) module.
## Related pages
- [Area overview page with navigation](/learning-model-your-business-structure.md)
- [Previous page: Data model extensibility](/learning-model-your-business-structure/extensibility/data-model-extensions.md)
- [Next page: Merchant Center Custom Applications](/learning-model-your-business-structure/extensibility/mc-extensions.md)
- [Search documentation and API specs](/search.md)