Infrastructure:
Databases & State

Parke Godfrey
14 September 2012
CSE-2041

Credits

These slides borrow from the following sources.

State
What is state?

Computer Programs: Stateless or Stateful?

HTTP

HTTP in itself is stateless.

Then again, what does it mean for a protocol to be called stateless or stateful?

The initial concept of WWW was for HTTP exchange to be stateless.


Why have HTTP be stateless?

  • This is efficient.
  • It is / was sufficient for what WWW is / was intended for.

“Web 1.0” (stateless)

“Web 2.0” (stateful)

Stateless / Stateful Trade-off: Session

Storing Information

The Web Ecosystem

State
Use the Web Server Process's State?

Use a Map Collection:

Map<String, Student> sis = new TreeMap<String, Student>(); 

Student s = new Student(“123456789”, …); 
sis.put(“123456789”, s); 
… 

String id = input.nextLine(); 
if (sis.containsKey(id)) 
{ 
output.println(sis.get(id).getGpa()); 
} 

Server Process keeps track
Problems?

Database Systems
...to the rescue!

Database Service
Data Independence

Databases
Transactions

A transaction is a change to, and / or a retrieval from, a database.

Atomicity
All or Nothing

All the (primitive) actions of a transaction should occur and commit, or none should.

transfer(account X, account Y, amount M) {
    X.balance =- M;
    Y.balance =+ M;
}

What if X.balance < M?

Consistency (Data Integrity)

Integrity rules can be added to a database.

E.g.,

This means the database system must deny (rollback) any transaction that would result in inconsistent data in the database.

Isolation

Durability (Permanence)

Once a transaction updating the database commits, that new data (the update) is

Database Server “Protocol”

How to “talk” to a database server to

Such a “protocol” is complex, almost like a programming language! It is called a “query” language.

SQL is a standardized query language for relational database systems.

Can only “talk” to the database via SQL!

The Relational Model

DBMS Architectures