views:

944

answers:

4

I am building an application in Java (with a jQuery frontend) that needs to talk to a third party application. it needs to update the interface every two seconds at the most.

Would it be a good idea to use comets? If so, how do they fit into the picture?

What other means/technologies can I use to make the application better?

The application will poll stock prices from a third party app, write it to a database and then push it to the front end every second, for the polling, I have a timer that runs every second to call the third party app for data, I then have to display it to the front end using JSP or something,

well at this point im not sure if I should use a servlet to write this out to the front end, what would you recommend? how should I go about it?

is there any new technology that I can use instead of servlets?

I am also using Berkeley db to store the data, do you think its a good option? what would be the drawbacks, if any for using berkeley..

im absolutely clueless so any advice will be much appreciated.

Thanks!

edit : I am planning to do this so that a deskop app constantly polls from the thrid part and writes to the database and a web app only reads and displays from the database, this will reduce the load on the web app and all it has to do is read from db.

+1  A: 

PostgreSQL is probably the right database. It's a little more enterprisy than MySQL. As for the front-end, there's lots of stuff that can go "on top" of servlets, SpringMVC, Tapestry, and so on and so forth. The actual servlet implementation will be hidden from you.

Many will suggest, and it's probably not a bad suggestion to use Spring to configure the application and to do any dependency injection.

If you're looking for something a little more lightweight, you might consider grails. It's quick to develop with and becoming mature.

Really though, it's kind of hard to recommend things without knowing what kind of "production" environment this would be. Are we talking lots of transactions? (sure, it's a stock trading program, but is it a simulation with a small number of users etc...) It's fun to suggest things, but if you're serious, I'm not sure I would start a major project like this. There are lots of ways to do this, and lots of ways to do this wrong.

altCognito
Well, I understand where you are coming from but I hvae to start somewhere, maybe work progressively towards it, I know there is a lot of things we can get wrong, but with some good advice, I can probably not get most of it right :) the application has a lot of transactions as in it updates and stores values to the db every second (atleast) and then my client has got some corporate customers so there will be a fair bit of users using it, will eventually grow bigger in a couple of years but I need advice to build it so that it wont stuff up.Thanks for all your advice, it was really good :)
Mponnada
also, edit : I am planning to do this so that a deskop app constantly polls from the thrid part and writes to the database and a web app only reads and displays from the database, this will reduce the load on the web app and all it has to do is read from db.
Mponnada
+5  A: 

Take a look at using a web application framework instead of Servlets - unless it's a really basic project with one screen. There are lots in the Java world unfortunately and it can be a bit of a minefield. Stick with maybe SpringMVC or Struts 2, the worst part is setting these up, but take a look at a sample application plus a tutorial or two and work from there.

http://www.springsource.org/about

http://struts.apache.org/2.x/index.html

Another option to look at is using a template framework such as Appfuse to get yourself up and running without having to integrate a lot of the framework together, see:

http://appfuse.org/display/APF/AppFuse+QuickStart

It provides you with a template to setup SpringMVC with MySQL as a database plus Spring as an POJO framework. It may be a quick way to get started and up and building a prototype.

Judging by your latency requirement of 2 seconds it would be wise to look at some sort of AJAX framework - JQuery or Prototype/Scriptaculous are both good places to start.

http://jquery.com/

http://www.prototypejs.org/

In terms of other technoloqies to make things better you will want to consider a build system, Ant/Maven are fine with Maven the slightly more complex of the two.

http://ant.apache.org/

http://maven.apache.org/download.html

Also, consider JUnit for testing the application. You might want to consider Selenium for functional testing of the front end.

http://www.junit.org

http://seleniumhq.org/

Jon
hi, thanks for ur advice, it was very helpful, also, I am planning to do this so that a deskop app constantly polls from the thrid part and writes to the database and a web app only reads and displays from the database, this will reduce the load on the web app and all it has to do is read from db.
Mponnada
+2  A: 

I think you should focus on your architectural design before picking technologies with a focus on scalability and extendability. Once an architectural design is in place you can look to see what's available and what you need to build, all of which should be pretty obvious.

While not directly comparable look at how Google, eBay and YouTube deal with the scalability problems they face. While a trading system won't have the issues these guys have with sheer numbers of users, you'll get similar problems with data volumes and being able to process price ticks in a timely fashion.

The LSE has getting on for 3000 names, multiply this by the 10 or so popular exchanges round the world and you've got a lot of data being updated continuously over the period each market is open. To give you an idea of what involved in capturing data from a single exchange take a look at http://kx.com/.

From a database perspective you've going to need something industrial strength that allows clustering and has reliable replication - for me this means Oracle. You also want to look at a Time-series Database Design, which in my experience is the best way to build this sort of system.

The same scaling and reliability requirements will apply to your app servers, with JBoss being the logical choice there, although I'd also consider the OSGi Spring Server (http://www.springsource.com/products/dmserver) as its lightweight nature could make it faster.

You'll also want Apache servers for load balancing and to serve static content - a quick Google will turn up stacks of information on that so I won't repeat it here.

Also forget polling, it doesn't scale. Look at using messaging and consumer processes for the cross-process communication, events and worker threads for the in-process communication. Both techniques achieve a natural load balancing effect that can be tuned by increasing the number of consumer processes or worker threads as need be.

Also a static front-end isn't going to cut the mustard, IMHO. Take a look at what's out in the market already - CNC Markets, IG Index, etc all have pretty impressive real-time trading apps.

As an aside, assuming this is a commercial project and not meaning to put a downer on the whole thing, companies like CNC Markets, IG Index, etc make their money from trading fees, the software being a means to an end, which you get access to for free simply by having an account. The other target for the trading software is commercial institutions such as the banks, investment managers, etc. I'd want a pretty watertight plan for how I was going to break into either of these markets before expending too much time and effort.

Nick Holt
+3  A: 

Is this really a stock trading application? Or just a stock price display application? I am asking because from your description it sounds like the latter.

How critical is it that data is polled every second? Specifically would it matter if some polls are a second or two late?

If you are building a stock trading application (where the timing is absolutely critical), or if you cannot afford to be delayed on your polling, I'd recommend you have a look at one of the Java Real Time solutions:

Other than that, my only advice is that you stick to good OO design practices. For instance, use a DAO to write to your database, this way, if you find that Berkeley DB isn't quite for you, you can switch to a relational database system with relative ease. It also makes it easy for you to move on to some database partitioning solutions (e.g., Hibernate Shards) if you decide you need it.

While I may have my own technology preferences (for instance, I'd choose Spring MVC for the front end as others have mentioned, I'd try and use Hibernate for persistance), I really cannot claim that these would be better than other technologies out there. Go with something you are familiar with, if it fits the bill.

Jack Leow
Hi, Thanks for ur comments, they were really helpful, I must have made it more clear in the question, I am not building a Stock Trading application but a price display application as you said, sorry about the mistake.
Mponnada