Follow these best practises to develop resilient and well performing
Use an asynchronous programming model
All calls in the Diffusion™ API are asynchronous. Ensure that you
code your client using asynchronous models to gain the advantages this provides.
Asynchronous calls remove the possibility of your client becoming blocked on a call.
The Diffusion API also provides context-specific callbacks,
enabling you to pass contextual information with a callback, and a wide range of
Write good callbacks
The Diffusion API
invokes callbacks using a thread from Diffusion
thread pool. Callbacks for a particular session
are called in order, one at a time. Consider the following when writing callbacks:
- Do not sleep or call blocking operations in a callback. If you do so, other
pending callbacks for the session are delayed. If you must call a blocking
operation, schedule it in a separate application thread.
- You can use the full Diffusion API to make other
requests to the Diffusion server. If you want to make many
requests based on a single callback notification, be aware that Diffusion client flow control is managed
differently in callback threads. Less throttling is applied and it is easier
to overflow the Diffusion server by issuing many thousands of
requests. If you have a lot of requests to make, it is better to schedule
the work in an application thread.
Use a modular design
API provides interfaces on a feature-by-feature basis.
There is a clear delineation between features. At runtime, the client starts only
those services that it uses.
You can take advantage of the modular design of the Diffusion API
by designing multiple smaller and more modular control clients. Smaller modules are
easier to design, maintain and keep running. Develop separate clients for different
control responsibilities. For example, have a client or set of clients responsible
for authentication and a different client or set of clients responsible for creating
Also consider separating the responsibility for different parts of the topic tree
between clients. For example, have a client or set of clients responsible for
updating the Tennis branch of the topic
tree and a different client or set of clients responsible for updating the Rugby branch of the topic tree.
Make your client resilient and defensive
If the Diffusion server restarts, all topic information — tree
structure and topic state — is removed, all subscription information is
removed, and all clients are disconnected. Security and authentication information
If your client disconnects and cannot reconnect to the same session, all of its
subscriptions and any handlers it has registered are lost.
Ensure that you program your clients to handle and respond to these