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 a web application requiring a middle-tier language to communicate between an oracle database and math routines on a Linux server and a flex-based application on a client. I'm not a software expert, and need recommendations for which language to use for the middle-tier.

The math routines are currently in Matlab but will be ported to C (or C++) as shared libraries. Thus, by default there's some C or C++ communication necessary. These routines rely on FFTW (www.fftw.org), which is called directly from C or C++ (thus, I don't see re-writing these routines in another language).

The middle tier must manage traffic between the client, the math routines, and the Oracle database. The client will trigger the math routines aynchronously, and the results saved in the db and transferred back to the client, etc. The middle-tier will also need to authenticate user accounts/passwords, and send out various administrative emails.

Originally I thought PhP the obvious choice, but interfacing asychronously multiple clients with the C or C++ routines doesn't seem straightforward. Then I thought, why not just keep the whole middle tier in C or C++, but I'm not sure if this is done in the industry (C or C++ doesn't seem as web-friendly as other languages). There's always Jave + JNI, but maybe that introduces other complications (not sure). Any feedback appreciated.


migration rejected from stackoverflow.com Jul 29 '13 at 14:11

This question came from our site for professional and enthusiast programmers. Votes, comments, and answers are locked due to the question being closed here, but it may be eligible for editing and reopening on the site where it originated.

closed as off-topic by gnat, World Engineer Jul 29 '13 at 14:11

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions about what language, technology, or project one should take up next are off topic on Programmers, as they can only attract subjective opinions for answers. There are too many individual factors behind the question to create answers that will have lasting value. You may be able to get help in The Whiteboard, our chat room." – gnat, World Engineer
If this question can be reworded to fit the rules in the help center, please edit the question.

3 Answers 3

I have ran into a similar situation when I wanted to make a web app for exposing large, data intensive computations which would generate neural networks and run sample data through them to see how various algorithms perform. Based on my experience, I think you should break up your app into the following parts:

  • Frontend / Web App
  • Middle Tier / Web Services
  • Backend / Math routines

Frontend / Webapp would consist of the flex app or any other app written in Ruby / Python / Perl / PHP or whatever is your favorite web scripting language. This frontend tier would communicate with your middle tier purely through Web Services - REST / SOAP - take your pick.

The Middle Tier would consist of Web Services written in Java using something like Jersey (or whatever Java Web Services framework you'd like - take your pick). The data access & authentication can be done easily using Java's plethora of data access frameworks. This middle tier can talk to the 'compute' Backend using:

  1. JNI
  2. RPC / thrift / avro or whatever.

The backend could be written in pure C and then wrapped in JNI or it would expose it's functionality using an RPC mechanism - xmlrpc, thrift, avro, protocol buffers etc.

If you decide to take the JNI route then you can implement Queuing, Backgrounding of task extremely easily using Java threads / ExecutorService etc. Also, you would not have to talk to Oracle natively through C/C++ because you can always use Java for data access while the C/C++ library only processes it. But JNI is prone to issues since it's talking to C/C++ code which when not written correctly can lead to coredumps or memory leaks and make your application unstable.

If you decide to take the RPC route then you possibly CAN cut out the Java Middle Tier in which case your entire MT & BE would be written in C/C++. If that's the case I would expect that you'd use probably expose your webservices by writing them as Apache DSOs. AND you'll have to write your own backgrounding / queuing mechanism. This is the harder, less maintainable route IMHO.

Also, the advantage of dividing up your app into these layers gives you great control over replacing your FE / MT without really bothering to replace your BE which is great when you decide you'd like to use Scala instead of Java or you'd like to create an iPhone / iPad / Android / WebOS app - you can reuse your webservices - yay! ;)

Thanks, my app requirements are the same as yours. I've divided it up into FE, MT, and BE. My question is which language to use for MT? Java talking to C++ using JNI seems not so robust. Using C/C++ as MT seems too complex. Any other options you'd recommend? –  gkdsp Nov 19 '11 at 17:42
As I mentioned in my original answer, you can always go the Java <-RPC-> C/C++ route. This is a robust and extensible solution. Infact, you can bypass the whole Java layer but I would not recommend it as, you'd have to write all sorts of APIs in C/C++ which is not fun to do. Java can save you a lot of time on APIs that derive on top of the C/C++ APIs. Also, don't be afraid of using JNI. JNI is 'fragile' only if the underlying C/C++ code is written in a bad, incomprehensible and buggy way. –  void_ptr Nov 20 '11 at 20:18
Thanks for clarifying. –  gkdsp Nov 22 '11 at 23:41
makes sense, but if your back-end stuff is C++, you might as well use a C++ web framework (like cppCMS or ATLServer)(or just implement web services using gsoap) for your middletier, which would not increase complexity, but would make maintenance easier - as you'd have 2 languages instead of 3 to manage. –  gbjbaanb Apr 27 '12 at 23:46

I would suggest using node.js. Because of the fast implementation of it's asynchronous APIs, it is perfect as a middle tier. One can also extend node.js with C++, however the execution model in node.js is single threaded, so you should always make such extensions asynchronous. Alternatively you can just launch a C++ process and communicate with it over stdin/stdout with some lightweight protocol.

node.js is indeed a very promising technology, but using it in production at the current time (2011/11) seems rather adventurous to me. (I'll wait one year for it to stabilize) –  Offirmo Nov 2 '11 at 13:26
@Offirmo: We are using it as a TCP-gateway for an MMORPG. There have been no problems thus far, with up to 2000 concurrent users. PHP and MySQL have both proven less reliable. –  back2dos Nov 2 '11 at 13:36
cool ! I'll have a look. By "stability", I referred rather to API and usage stability, i.e. not big parts of the framework changing at each version (like earlier revisions of Ruby on Rails). –  Offirmo Nov 2 '11 at 16:12

in your request, I read

authenticate user accounts/passwords, and send out various administrative emails

So it seems to me that you that what you need is close to a full web app able to call C++ and work asynchronously. Nearly all web frameworks are able to do that.

I suggest two possibilities :

  1. Ruby on Rails with a native interface to C++ and delayed_job
  2. Wt C++ web framework with various libs for delayed jobs and sending emails

Now it's up to you to assess if you only need a very small web app and are able to code it "from scratch" (CGI or mongoose) or if you web app will grow and then you need to learn a new language/framework.

+1 for mentioning Ruby; while I don't care for it too much personally, it would seem to be a reasonable possibility for this sort of task. –  Donal Fellows Nov 2 '11 at 11:25
I'm committed to Flex/AS3 for the front-end. Looking for back-end language to interface with C or C++ routines for math processing. Correct me if I'm wrong but it seems like I need to jump through a lot of hoops to use PhP to interface with C; what about Ruby, Python, ... ? Any one seem better suited than the others? The ap's needs are not too demanding for back-end other than communicating w/ front end, C/C++ routines, database, apache. –  gkdsp Nov 14 '11 at 4:08

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