Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

I have designed a RESTful API and I am now working on creating a web application to use the service.

One thing I am struggling with is how to manage alerts in the web application (similar to the alerts stackoverflow gives in your profile for a new answer, response etc).

Basically the web application is a workflow between a user and his clients. Certain tasks have to be completed in order, and the web application alerts both the user and his clients of any actions. The user also gets alerted to any client actions that are outstanding.

The way I have my architecture setup at the moment is that the API has no knowledge of alerts. It simply stores the resources that are retrieved by the web application. To work out if an alert needs to be displayed, the web application looks at all the resources, and based on a set of rules, decides what alerts need to be displayed.

The problem I have is that I'm not sure this is a very efficient way to do things. There are a number of different alerts that can be displayed, and they depend on different API resources which will all need to be retrieved when a user or client logs in.

My question: Is this the best way to achieve what I want, or are there other methods which are better to use and will help decrease web application load time and api calls?

share|improve this question
add comment

2 Answers 2

up vote 1 down vote accepted

So one thing you could do is to make the checking of rules asynchronous. Once the resource is created (maybe as an aspect) you put a reference to the posting in Rabbit MQ, Active MQ or even a database table that's periodically swept by another process. Using aspects means your API need not know anything about alerts. (Although you should be careful about what verbs you use with these side effects - i.e. POST is your friend but GET would be inappropriate).

Can you be a little more specific? Maybe disclose the frameworks or language? There might be a more better way to do this than AOP.

share|improve this answer
    
thanks. Have updated question. PHP using Laravel. –  Gaz_Edge Mar 3 '13 at 19:26
    
I don't know Laravel, but from skimming the docs it looks like an after filter might do the trick. With PHP you're in luck because you have a lot of options. There are multiple rabbit clients, for Active MQ there's the PHP Stomp client, etc. If you're on AWS there's SQS, etc. Depending on your hosting, you could even write the event consumer in PHP. Does this help? –  ipaul Mar 3 '13 at 19:44
    
Thanks for the answer. Any suggested reading you could point me too? Still a little clueless atm –  Gaz_Edge Mar 3 '13 at 21:02
    
    
github.com/videlalvaro/php-amqplib –  ipaul Mar 4 '13 at 15:45
show 3 more comments

You are the best person to answer your own question.

Are alerts integral part of the system? Let's say tomorrow you write a mobile app that interacts with your server. Is it reasonable to assume that it will need alerts too? Or are alerts specific to the web site use case? If the answer to the first question is yes, then you probably want to have the server handle alerts. This way when you get to write your moobile app, you don't need to replicate the alerts code you wrote for the web site. But if alerts are specific to the web site use case, you can and should leave the logic in the web site in order to keep the server's api clean and focused.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.