I'm a front end developer...I've never done ANY backend, although I did take a course in databases once. (I have a comp sci degree; I'm a competent programmer, I just haven't done any backend web stuff before.)

So I'm trying to figure out how the framework relates to the database. Presumably they're set up separately, and the framework receives requests from the website and sends them to the database, then receives the response and handles it appropriately to deliver the content correctly? It's basically a complex intermediary for all the web-app logic? Am I far off?

Need a good explanation of this.


There are many possibilities to connect a web-app to a database (and a lot of different databases to choose from).

I think you should first consider the normal case (as e.g. most used in the RoR community):
a relational DB and a ORM (the object relational mapper - in RoR it is ActiveRecord based on the active record pattern).

a very high-level (and superficial) introduction:

  • the database is a separate entity and process.
  • the app defines models that describe both the tables in the relational database (RoR will create the necessary SQL commands) and the the way the data in the database can be accessed and modified from the web-app using objects and properties.
  • in your web-app-code you access the database only by interacting with those models. e.g. in RoR:
    1. the users make requests to the web-app
    2. the requests are handled in the controller.
    3. the controller creates or retrieves records (e.g. by invoking find(<id>) on the class object) from the DB. these records appear as objects (or arrays of objects).
    4. the controller modifies them, and
    5. stores the result back to the DB (e.g. by invoking save() on the object).
    6. the response e.g. shows the result to the user.
  • I think this is the most thorough of the current answers, but it's worth noting that "you access the database only by interacting with those models" is somewhat simplistic. Instead, it's best to say that you usually interact through the models; performance sometimes dictate that you ditch the ORM. A better way of saying it is that the framework manages your database connections, offers an interface to them, routes requests to the appropriate pieces of code, and (usually) provides templating functions to reduce the boilerplate inherent in HTML/CSS. – asthasr Feb 26 '13 at 0:00
  • yes, you are right. this statement was meant in the context of a simplistic introduction to make clear that for all normal operations you interact with the models. in addition to the case you mention (performance), usage and network analysis (if there are complex relations between the users) are frequently done without using the ORM but by directly querying the DB. – kr1 Feb 26 '13 at 5:24

Presumably, as a front end developer, you know how your Rails controller handles standard HTTP requests. Rails MVP framework also has models. Rails has support for ActiveRecord models. These are basically classes that are linked to some underlining database. In your controller, you can make calls on this model to read or modify data in the database.


The way frameworks function in relation to the user's request and the database is not very different from any tiny piece of code acting as an intermediary between the two. Any 'web-app logic' is situation between the two, be it a complex MVC/MVP framework or a 5 line PHP file. They function to determine the user's request, make a connection to the database and retrieve stuff, and present this to the user.

A framework subdvidides several steps that often occur in this intermediary step. As the name implies MVP has Models that structure the data retrieved from the database in a useful way, a View where the end-result is given to the user, and a Presenter which ties these two together and may perform some additional logic.


Where as a website that doesn't change can just serve static pages, a web application like amazon has got a lot to do to present a page that represents a product: put simply, it can retrieve the product details based on an identifier passed in and build a web page that displays those details.

I would say a web framework relates to a database in the following way:

"A web framework is used to build/run a program that requests from a webserver run to build responses that can use data stored in database."

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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