OCPI uses two main interaction patterns: pull (the consumer asks for data) and push (the producer sends data when it’s ready). Different modules use different patterns, and getting the choice right per module matters for both correctness and performance.
This article explains the two patterns, which OCPI modules use which, and the operational tradeoffs. If you are new to the protocol, start with what OCPI is for the role and module basics.
The two patterns
Pull (request-response): the consumer initiates the conversation. Sends an HTTP GET to the producer’s endpoint. Gets a response with the current state.
[ Consumer ] -- GET /locations --> [ Producer ]
[ Consumer ] <-- locations data --- [ Producer ]
Pull is what you’d call a normal REST API pattern. Stateless, idempotent (in the HTTP sense), and predictable.
Push (server-initiated): the producer sends data to the consumer’s endpoint when something happens. The consumer must have a URL the producer can POST/PUT to.
[ Producer ] -- PUT /sessions/{id} --> [ Consumer ]
[ Producer ] <-- 200 OK ----------------- [ Consumer ]
Push is event-driven. The producer doesn’t wait for the consumer to ask; it sends the update right away.
OCPI uses both patterns, depending on the module and the use case.
Module-by-module pattern guide
A reference for which OCPI modules use which pattern.
Locations: pull-and-cache + push updates
Initial sync: the consumer pulls (GETs) the producer’s Locations once. Returns all current Locations. Possibly paginated.
Updates: the producer pushes individual Location updates as they happen. PUT to the consumer’s Locations endpoint with the changed Location.
In practice, many consumers do a periodic re-pull (daily or weekly) as a safety net against missed pushes. Locations data doesn’t change frequently so the redundancy is cheap.
The PUT and PATCH rules for each level, including the parent last_updated requirement, are in the OCPI Locations module reference.
Sessions: push primarily
The producer (CPO) pushes Session updates to the consumer (eMSP) as the session progresses.
A typical session generates 3-10 pushes:
- Session START (when the user begins charging).
- One or more interim updates (state changes, periodic energy updates).
- Session END.
Pull is also supported: the CPO’s Sessions Sender interface offers a paginated GET of the sessions last updated between date_from and date_to. It returns a list, not one session by ID, and push stays the primary delivery mechanism.
CDRs: push preferred, pull to recover
CDRs are the immutable billing records. The producer (CPO) pushes the CDR to the consumer (eMSP) once the session is complete and the CDR is final.
Each CDR is pushed once, as a POST, and the consumer acknowledges it with an HTTP 2xx plus a required Location header pointing to its stored copy. The spec says the receiver SHOULD answer 201 Created for a new object (200 for an update), but many eMSPs answer 200 OK, so a CPO should treat any 2xx as delivered. If the push fails, the spec says not to queue it and send it again later. The CDR is not lost, as long as the CPO offers the CDRs Sender (GET) interface. It then stays available for the consumer to pull. A CPO that relies on the no-queue rule needs to implement that GET.
There is a pull side too. The CPO’s CDRs Sender interface offers a paginated GET filtered by date_from and date_to. The 2.2.1 spec says push is the preferred model, and that this GET can be used alongside push to retrieve CDRs missed during the eMSP’s downtime, or by an eMSP that does not support push at all.
Tariffs: push primarily, pull to sync
The producer (CPO) pushes new and updated Tariffs to the consumer with PUT, and removes them with DELETE. The 2.2.1 spec advises push from Sender to Receiver during normal operation.
The CPO’s paginated GET is for the first sync after a connection is set up, and for when the receiver is not sure its tariff cache is still current. An eMSP that does not support push pulls the full list instead and replaces its cached copy.
The exact endpoints, and which methods each side accepts, are in the OCPI Tariffs module reference.
Tokens: query-on-demand (pull) + push for whitelisting
When a CPO needs a live decision on a user identifier (its token’s whitelist value is NEVER or ALLOWED_OFFLINE, or ALLOWED and the token isn’t in the CPO’s cache), it queries the eMSP in real time: a synchronous POST to the eMSP’s tokens/{token_uid}/authorize endpoint, which answers with an allow-or-deny verdict.
Separately, the eMSP can push its whitelist (or pieces of it) to CPOs that support local authorization caching.
The pattern is mixed: real-time pulls for authorization, optional push for caching.
Commands: push (asynchronous)
A consumer (eMSP) sends a Command request to the producer (CPO). The CPO acknowledges the request, processes asynchronously, then pushes a Command response back when done.
The asynchronous nature is because commands like RemoteStart have a real-world delay, because the charger has to receive the command, act on it, and respond. The whole flow can take seconds to a minute.
HubClientInfo: pull-and-cache + optional push
Standard pull pattern. The hub publishes its client list; consumers pull. Optional push for subscribers who want real-time updates.
Credentials: synchronous request-response
The Credentials handshake is a pure pull/POST pattern. PUT and POST messages exchanged at registration time. No background push.
ChargingProfiles: push from eMSP to CPO
The eMSP pushes a ChargingProfile to the CPO for a specific session. The CPO acknowledges and applies it.
Why this mix
Each module’s pattern was chosen with its specific needs in mind.
Locations is mostly static data with occasional updates. Pull-and-cache is efficient. Push updates the cache without full re-pull.
Sessions are events. Push is the natural pattern, because the producer knows when the event happened and the consumer wants it immediately.
CDRs are billing-critical. Push delivers them quickly; the paginated GET is the recovery path for anything missed while the link was down.
Tariffs are reference data that drivers see as prices, so the spec advises push during normal operation and keeps pull for syncing a cache.
Tokens are mixed-frequency. Real-time queries need pull (synchronous). Whitelisting needs push (push the list once, query offline).
Commands are user-initiated actions. Async push handles the real-world delay.
Choosing patterns module by module gives you the right efficiency/correctness tradeoff for each data type. The cost is that an OCPI implementation must support multiple patterns rather than one.
Push design: doing it right
If you’re implementing the receiving side of a push pattern (Sessions, CDRs, ChargingProfiles, etc.), several things matter.
Idempotency. The same message may arrive twice, for example after a timed-out push or an overlapping catch-up pull. Deduplicate by the natural key (session_id for Sessions, cdr_id for CDRs).
Acknowledge fast. Return an HTTP 2xx quickly (201 is what the spec recommends; a sender should still accept 200). If you have heavy processing (database writes, downstream notifications), do them async after returning.
Return meaningful errors. If you can’t process the push (validation failure, your system is down for the partner), return an OCPI status code that says why. A 2xxx code tells the sender the message itself is wrong. If your system is down, it is your side’s job to catch up with a GET when it is back.
Authentication. Verify the bearer token on every incoming push. Don’t trust the source URL alone. See OCPI security and authentication for how tokens are exchanged and rotated.
Rate limiting. A misbehaving partner might push aggressively. Protect yourself with per-partner rate limits.
Logging. Log every received push for audit. Include enough detail to reconstruct what happened if a partner disputes.
Push design: doing it right (sender side)
If you’re implementing the sending side (a CPO pushing Sessions/CDRs to eMSPs):
Don’t queue failed pushes. The 2.2.1 spec says a POST, PUT or PATCH that fails or times out SHOULD NOT be queued and sent again later. Log the failure: when the connection is back, the receiver GETs the current state. That only works if you offer the GET side, so implement the Sender interface for the modules you push. A 4xx is a different problem. The receiver has told you the message itself is wrong, so fix the data, not the delivery.
Don’t block on a partner. One partner’s endpoint being down must not slow your own system. Push asynchronously, with a short timeout.
Per-partner monitoring. Some partners are reliable; some are flaky. Track failed pushes per partner and alert when one stays unreachable.
Deduplication keys. Generate unique IDs (session_id, cdr_id) that survive redelivery cleanly.
Eventual consistency. Accept that some pushes arrive late. Design downstream systems to handle late arrivals (a CDR that arrives 6 hours late is still a valid CDR).
Observability. Track per-partner push success rates, latency, failed pushes. Spot problems early.
Pull design: doing it right (consumer side)
If you’re pulling from a partner’s endpoint:
Cache aggressively. Pulled data is often stable (Locations, Tariffs). Don’t re-pull on every operation.
Respect pagination. Always follow the Link header for next pages. Don’t assume the first page is everything.
Background refresh. Schedule pulls on a sensible interval (daily or weekly for Locations, more frequent for Tariffs). Don’t pull on demand for hot-path operations.
Handle 304 Not Modified. If the partner supports it, conditional GETs save bandwidth on unchanged data.
Failure tolerance. A failed pull shouldn’t break your application. Use last-known-good data and alert on staleness.
Pull design: doing it right (producer side)
If you’re serving GET endpoints:
Pagination is essential. Large result sets break the world. Default page sizes of 100-1000 are reasonable.
Filtering and search. Support date-range filters for time-series data (Sessions, CDRs).
ETags / Last-Modified. Support conditional GET so consumers can skip unchanged data.
Performance. Locations and Tariffs GETs may run frequently. Index appropriately.
Rate limiting. Even pulls can be abusive. Protect against runaway consumers.
Mixed patterns in practice
Real-world OCPI implementations often blend the patterns.
Example: a CPO running new chargers comes online.
- The CPO’s CSMS publishes new Locations.
- It pushes Location PUTs to all connected eMSPs (push for the new data).
- Some eMSPs also do a periodic re-pull (pull for safety net).
- When a user taps, the CPO checks the Token with the eMSP via a real-time query (a POST to the eMSP’s authorize endpoint) whenever the token’s whitelist value calls for a live check:
NEVER,ALLOWED_OFFLINE, orALLOWEDon a cache miss. - As sessions run, the CPO pushes Session updates (push).
- Session completes; CPO pushes CDR (push; anything missed is pulled later).
- eMSP pulls Tariffs occasionally to check its rate cache against the CPO’s (pull as a safety net).
sequenceDiagram
participant CPO
participant eMSP
CPO->>eMSP: PUT Locations (push new)
eMSP-->>CPO: GET Locations (re-pull safety net)
CPO->>eMSP: POST Token authorize (real-time query)
CPO->>eMSP: PUT Session updates (push)
CPO->>eMSP: POST CDR (push)
eMSP-->>CPO: GET Tariffs (pull and cache)
A single connection between two parties involves all patterns.
Common pitfalls
Treating push as guaranteed delivery. A push can fail, and the spec says not to queue it for later. Check every response, log failures, and make sure the receiving side runs a catch-up GET after any outage.
Polling when you should push. “I’ll just poll the Sessions endpoint every minute” misses fine-grained updates and burns bandwidth. Implement push instead.
Push without idempotency. Receiver gets duplicates; data is corrupted. Always idempotent.
Ignoring pagination on pull. First page is not the whole story.
Caching pulled data forever. Tariffs change; Locations get added; your cache goes stale. Define cache-invalidation rules.
The honest summary
OCPI’s pull/push pattern mix is intentional. Each module has data characteristics that justify its pattern choice. Implementations have to handle both. The biggest mistakes are treating push as fire-and-forget, ignoring idempotency, and polling when push is the better choice. Most of these recur, and common OCPI integration pitfalls collects the field-tested list. Get the patterns right per module and your OCPI integration will be both performant and correct.