So much these days is about distributed resource management. That’s anything that can be created and destroyed in the cloud. Proper management is especially important when the resource’s existence is tied to a real economy, e.g. your user’s credit card.
Above is a state machine required to ensure that resources created in AWS EC2 are not lost, i.e. do not have to be manually cleaned up. The green arrows represent error free flow. The rest is about error handling or external state changes, e.g. user terminated operation. This is from before EC2 supported idempotent instance creation.
The state machine rewritten to use idempotent instance creation,
What’s going on here? Handling failure during resource creation.
The important failure to consider as a client is what happens if you ask your resource provider to create something and you never hear back. This is a distributed system, there are numerous reasons why you may not hear back. For simplicity, consider the client code crashed between sending the request and receiving the response.
The solution is to construct a transaction for resource creation. To construct a transaction, you need to atomically associate a piece of information with the resource at creation time. We’ll call that piece of information an anima.
In the old EC2 API, the only way to construct an anima was through controlling a security group or keypair. Since neither is tied to a real economy, both are reasonable options. The non-idempotent state machine above uses the keypair as it is less resource intensive for EC2.
On creation failure and with the anima in hand, the client must search the remote system for the anima before reattempting creation. This is handled by the
GM_CHECK_VM state above.
Unfortunately, without explicit support in the API, i.e. lookup by anima, the search can be unnatural and expensive. For example, EC2 instances are not indexed on keypair. Searching requires a client side scan of all instances.
With the introduction of idempotent RunInstances, the portion of the state machine for constructing and locating the anima is reduced to the
GM_SAVE_CLIENT_TOKEN state, an entirely local operation. The reduction in complexity is clear.
After two years, EC2 appears to be the only API providing idempotent instance creation. Though APIs are starting to provide atomic anima association, often through metadata or instance attributes, and some even provide lookup.
You should provide an idempotent resource creation operation in your API too!
 “in the cloud” – really anywhere in any distributed system!
 Making money from forgotten or misplaced resources is a short term play.
 Alternatively, you can choose an architecture with a janitor process, which will bring its own complexities.
 “in hand” – so long as your hand is reliable storage.
 After a quick survey, I’m looking at you Rackspace, RimuHosting, vCloud, OpenNebula, OpenStack, Eucalyptus, GoGrid, Deltacloud, Google Compute Engine and Gandi.