Justin Francis Self-Portrait

Monday, April 23, 2007

Pile of Scripts vs Application Server

When I first started doing some work with Java servlets, what struck me immediately was that the entire web application has a shared state that is wholly contained within itself. This differs from say, a pile of PHP scripts, which do not share any state except what they store in the database (ignoring sessions). More recently, I moved into Python where both were possibilities, but we chose to have a single Python process handle all incoming web requests, yielding an application server instead of a pile of scripts.

This was probably the most fundamental complaint I had with many scripting languages, but to my surprise, I could not find a single online discussion of this issue. So to break the ice, I believe there are four reasons why an "In-Memory" model makes things easier for developers: lower impedance mismatch, native messaging technique, DB as secondary system, and theoretical performance.

Assuming you are using a Domain Model, it is much more natural to assume "Identity Integrity" in your application; by which I mean if we have an object that represents a specific user in our application, it is much easier to understand the system as dealing the same single object instance instead of dealing with multiple copies that get synchronized with each other through the database on each request.

If you don't have any shared memory native to your application that persists between requests, then fundamentally, you are sending messages through the next best thing: the database. It seems that it is much more efficient and powerful to send messages using the native framework without requiring that message to pass through the database, with all the restrictions that may imply. While rather abstract, this difference may have more of an impact than you think as I describe next.

In an application server with a single state kept resident in the running instance itself, the database takes on very little significance. It literally becomes a secondary system that you use only to ensure that the next time the system comes up, it will be in roughly the state it was in when it went down. In other words, it is used for persistence only. This is important because it alters your perspective, which may alter the way you design your system.

Last, and probably least (as this is by no means the only factor, or even the most important factor) is the fact that if you are hitting the database to retrieve state on each request, you are doing way more work (and so is your database) than you need to. Who knows how much faster your system would run if instead of reading from a DB each time a page loads, it just looks up a username in an array in memory?

I guess the fundamental difference between these two is that with a pile of scripts, the DB is used to maintain application state as well as persist that state, whereas with a single-process, in-memory application, the DB is only used to persist changes to the application state which is just "there". I think you would be surprised at how liberating that concept is.


Anonymous said...

Saw your site bookmarked on Reddit.I love your site and marketing strategy.Your site is very useful for me .I bookmarked your site!
I am been engaged 5 years on the and loans If you have some questions, please get in touch with me.

Anonymous said...

After reading you site, Your site is very useful for me .I bookmarked your site!
I am been engaged 10 years on the Free finance personal software If you have some questions, please get in touch with me.

Unknown said...

coach outlet
tory burch outlet online
michael kors outlet
timberland canada
coach factory outlet
burberry handbags
pandora uk
true religion outlet
gucci outlet
coach outlet store online
louis vuitton outlet
michael kors outlet
ralph lauren uk
jordan shoes
louis vuitton
jeremy scott adidas
chanel handbags
cheap oakley sunglasses
jordan 11s
hollister clothing
copy watches
prada bags
p90x workouts
polo outlet
jordan retro 3
coach outlet
pandora jewelry
hollister co
retro jordan
pandora rings
coach outlet online
jordan retro 8
ray ban sunglass
air jordans
oakley frogskins

Anonymous said...

michael kors outlet
ralph lauren outlet
mont blanc pens
asics,asics israel,asics shoes,asics running shoes,asics israel,asics gel,asics running,asics gel nimbus,asics gel kayano
mulberry uk
swarovski jewelry
ralph lauren uk
longchamp pliage
pandora jewelry
thomas sabo uk
hollister shirts
adidas trainers
coach outlet
michael kors wallet
fitflops sale
true religion jeans
louis vuitton bags
adidas shoes
hermes bags
kate spade uk
toms outlet
louis vuitton outlet stores
louis vuitton neverfull sale
discount michael kors handbags
longchamp handbags
prada outlet
michael kors factory outlet
louis vuitton handbags
michael kors handbags
polo ralph lauren
true religion jeans
cartier outlet store
michael kors outlet
omega outlet

chenmeinv0 said...

michael kors outlet clearance
burberry outlet
louis vuitton purses
rolex watches outlet
louboutin pas cher
mbt shoes
louboutin shoes
coach outlet online
canada goose sale
cheap uggs
michael kors outlet
montblanc pens
cheap ugg boots
louis vuitton outlet
chanel outlet
fitflop sandals
coach outlet online
michael kors
coach outlet
adidas trainers uk
ugg outlet
jordan shoes
cavaliers jerseys
tiffany and co jewelry
cheap rolex watches
doudoune canada goose
chaussures ugg
ray ban sunglasses outlet
cheap jordan shoes
louis vuitton handbags