Back to EIP

PatternAn idempotent receiver is a receiver that can safely receive the same message multiple times.
How Ballerina helps

When implementing idempotent endpoints, such as HTTP PUT, users may use Ballerina to create logic that leaves the state in the same state even if the same message is received multiple times. Explicit de-duping can be implemented using Ballerina's rich set of packages to interact with databases and key-value stores, such as SQL and Redis.

Idempotent ReceiverMessageMessage Channel
import ballerina/http;

type OrderDetail record {
    string orderId;
    OrderStatus status;

enum OrderStatus {

final map<OrderStatus> orderStatuses = {};

service /api/v1 on new http:Listener(8080) {

    resource function put manage\-orders/[string orderId](OrderDetail orderDetail) returns
        OrderStatus? orderStatus = orderStatuses[orderId];
        if orderStatus == orderDetail.status {
            return http:STATUS_NO_CONTENT;
        } else {
            orderStatuses[orderId] = orderDetail.status;
            return http:STATUS_CREATED;