Let's say I want to build a backend app which will offer a REST interface to my iPhone music application, and this backend app has to retrieve data from several webservices, some in JSON, some in XML.
One approach would be to build an "adapter" layer which basically will receive the RESTful request from the iPhone app, and it will query the final endpoints, and then it will compose the final data which should be standardised in some way (for instance using the MRSS syntax).
My main question is how should I structure the whole system into tiers:
- Since the output of the REST interface I would like to be as good as possible, I would build some classes for the objects (music in this case) that it would define all the different entities and relationships like songs, albums, artists... etc.
- Then, I would develop some "adapters" that will transform the returned data from the providers (non standardised data) into my REST definition.
- One question is, should I cache the external endpoints using a cache layer like phpfastcache or should I store it once I have already transformed the data? In the case of storing the data once the data is "clean", should I normalize the data using a database for storing each attribute in a different column (year, genre, name, etc) or should I store the whole objects in a key/value database?
- Since some of the external endpoints I have to connect to are very slow, I would like also to setup a cron processes in order to retrieve the data, cause otherwise it would penalize the user responsiveness if the first time a user ask for that endpoint has not been already cached. Should I use a componente like Jobby for this? (https://github.com/jobbyphp/jobby)
Thanks!