App Engine: Entity life cycle webhooks in the Datastore admin interface
by gmosx, at 30 Jun 2010One of the fringe benefits of Google App Engine is the comprehensive administration control panel you get for free. From your application dashboard you have access to the datastore, logs, cron jobs, task queues, blobs, etc. You can set permissions, blacklist ips and switch between multiple (concurrently running!) versions of your app.
Arguably, the Datastore viewer/editor is one of the more interesting features of the admin interface. It 's also seriously flawed: it handles the entities as 'atoms', yet in real life entities participate in complex entity structures. More often than not, a change in one entity affects other entities in the 'graph'. The lack of support for life cycle events in the current version of the Datastore viewer renders it incapable of capturing such complex entity relations.
What do I mean by life cycle events? Events like entity creation, entity update and entity deletion. Mainstream ORM systems popularised callbacks like oncreate, onupdate, ondelete. Introducing such callbacks in the Java and Python APIs may be easy, but things get messy when you consider the ecosystem of alternative language implementations based on the Java API: developers using alternative languages would be forced to use Java to write the callbacks.
There is a more robust solution though. Google App Engine already leverages the power of webhooks in such APIs as taskqueue, email, xmpp and more. Webhooks can elegantly solve the life cycle management problem as well: when an entity is created, updated or deleted through the Datastore viewer a corresponding webhook is triggered. Let's say the user is playing with Article entities, the webhooks uris could be:
http://myapp.com/_ah/admin/datastore/le/Article/create/{key}
http://myapp.com/_ah/admin/datastore/le/Article/update/{key}
http://myapp.com/_ah/admin/datastore/le/Article/delete/{key}
Slightly more work than callbacks, but still simple and effective. If there is an even better solution, I would love to hear about it in the comments section.
Update: I want to make clear that this is a proposal not an actual feature!


