views:

24

answers:

1

I am trying to research error handling paradigms in web service client apps. I haven't found any good results on Google - perhaps I'm not searching using the right terminology. I will describe my imagined approach to error handling below. Can you name it?

Lets say our application is like iTunes but online. The user runs a JavaScript based client which interacts with a web service through AJAX. One of the things the user can do is to create 'albums' and then place 'songs' in them. At the API level this is represented by one API call to create a new album, and then one or more calls to associate an existing song with the new album.

Now a traditional client might pause the whole application until it has confirmed the album has been created. To make a snappier client we could optimistically assume the album creation API call will succeed, and immediately display the new album in the user's list. The user could start dragging songs into the new album even that the API call to create it is still pending behind the scenes. The API will catch up when it gets there.

In the unlikely case of an error (internet connection went down maybe) the app informs the user, pauses and retries the operation until it succeeds or the user quits. If the user quits, the application just forgets all uncommitted operations and the user loses a couple of actions.

What's the name for this kind of strategy? What's some good literature on the subject? Internet links?

+2  A: 

I think what you describe can be seen as some kind of "reliable messaging". I'm not aware that it's used for ajax based applications, and from my point of view your design has some weak spots:

Assume you will not have only two API calls but three or more. Imagine how complex your error handling and reporting will become. A call to an API method should be some kind of atomic operation, so you should wait for the response if the future logic depends on it.

If you want your client to be snappier: Why do you want to execute the "new album" call anyway? If you manage the album updates in the client, you don't need to create the album before sending the contents of the album.

A good API for such a client is something different than a "on the server" API. Perhaps it could help you to have a look at Fowlers "unit of work" pattern. It's for databases, but in my opinion the idea also applies to your setting.

Achim
Thanks for the feedback. I didn't go into detail in my post but in order to tackle the error handling I was going to simply queue up all API calls in the background and only run them in sequence. If one call fails, none of the subsequent calls will be made either. Then the error handling and report can simply be 'Your last changes couldn't be saved. Retrying now...' It would spin on the first item in the operations queue until it succeeds or the user gives up.
Alexander Ljungberg
I'm quite sure that this will not work in any non trivial application. How do you queue for example the call for "add song to album" as long as you don't have an album id returned from the server?
Achim
The Unit of Work pattern looks interesting, thanks. Regarding your comment, the future actions like 'add song to album' would use the 'album' object instance of the client. This instance would not know it's server side id initially but could still be referenced on the client side. Once the album creation operation finished, the instance would be updated with the server side id and the next action would know what it needs to do.
Alexander Ljungberg
Ok, your right. But that sounds like a lot of code not adding value but the possibility of bug. Depends on your requirements of course. Good look and please make the library available if it works fine! ;-)
Achim