views:

37

answers:

4

Is there a way to execute the backend code (ruby) in the web browser instead in a web application (rails)?

Cause I wonder why all the code should be executed in the server, isn't it bad architecture.

It's like the same concept of SVN, it is very dependent of the server, rather than having a more distributed architecture like Git, every client executes the backend code. In that way it will free performance load from the web server and it could handle more clients cause today's computers are quite performable on the client side.

The client will communicate with the database through the backend server, but the backend will not contain all the application code, just for the communication part. The server code on the client will be compiled.

Isn't this actually a better approach to solve performance load issues?

+1  A: 

Security.

If this was an e-commerce application, you most definitely don't want the client to run the backend code, as then some unscrupulous person could modify a financial transaction for example. It is much easier to control data and ensure its security when it all resides on the server (think health records).

Another example is form validation. While the client code can perform input validation, the fact that it's located on the client means it can be bypassed. That's why servers will (should) validate all user input before processing it, even if the client code has already performed validation.

In silico
Isn't the code safe if you compile everything into machine code? Isn't the code unreadable then and can't be modified?
never_had_a_name
@ajsie: No. Even if it is compiled to some form of bytecode, there will be someone will will dissemble it and figure out what it does. Also, someone can use a tool to monitor network traffic and reverse engineer what data is being sent.
In silico
+1  A: 

One problem with running code on the client is that you need to be much more careful of security issues. The server is a known/controlled environment, and can be well tested before deploying the application. If you're releasing the application publicly then you never know what the configuration of a client machine is going to be, so you may have to cater for different configurations, and your code is a lot more open to abuse, either accidentally or maliciously.

Andrew Cooper
+2  A: 

You can't run Ruby code in the browser, but you can certainly offload some things to it. Javascript and Flash are probably the most common languages for client-side scripting. The limitations of client-side work are mostly about security and data. For security purposes, many things have to be done server side. And typically your server has a much better connection to the data stores than the client will, so its often more efficient to do work on the server.

The most common reason to use heavy javascript/client side scripting is for responsiveness -- it's not so much that you've offloaded the CPU-intensive work to the client, but the client's perceived responsiveness will obviously be much better if they don't have to hit the server to perform an action.

Scott Stafford
+1  A: 

I think RIA applications built using Adobe Flex etc / Silverlight are moving in that direction itself. You should look at some of these if you want to do a lot of things on the client rather than the server.

However, there has always existed the old client - server paradigm of building applications. Technologies like VB6, Powerbuilder, Oracle2K etc and their current avatars like WPF/ Windows Forms/ Oracle Forms all provided with a way of doing more on the client side rather than doing everything on the server.

Also, moving all the application logic - other than DB communication logic - to the client means that you are moving back to the thick client way of doing things - which has its benefits but also its drawbacks compared to the thin client model of web applications.

The deployment / upgrades of thick client applications ; support for multiple client OS'es / varying client environments which could potentially make your application performance unpredictable are just some of the issues why there was a move away of thick clients to thin in the first place. Inspite of technologies like ClickOnce which help with deployment, these issues still exist - in varying degrees even today.

Hence its a tradeoff as to whether you choose a thick / thin client depending on your needs.

InSane