SimpleDB Amazon s database in the Cloud Ralf Westphal, ralfw@ralfw.de, http://www.ralfw.de Freier Autor, Berater, Entwickler und Trainer www.prodevcollege.de There is more than Hierarchical databases Relational databases Object oriented database Associative databases 1
There are Tuple Spaces A tuple space is an implementation of the associative memory paradigm for parallel/distributed computing. from http://en.wikipedia.org/wiki/javaspaces Tuple Space Tuples with different cardinality Just simple operations Read Write Take Notify Find tuples through template matching query by example source: http://www.isima.fr/~ponge/cours/programmation-avancee-0708/projet.html 2
Enter Amazon SimpleDB Amazon SimpleDB is a web service for running queries on structured data in real time. Amazon SimpleDB data model 3
Normalization is out Store data the object way 4
SimpleDB data model details Domains» identified by a string (UTF-8)» 100/account (beta)» 10 GB/domain (beta) Items» identified by a string (UTF-8)» unlimited number/domain Attributes» name-value pair (both UTF-8)» type-less values, just strings; automatically indexed» 256/item» 250 mio./domain» 1KB/attribute value SimpleDB operations Domains CreateDomain* ListDomains** DeleteDomain* Items/Attributes PutAttributes* (store/change an item) DeleteAttributes* GetAttributes (retrieve an item) Query** *subject to eventual consistency **paged result set 5
Raw calls to SimpleDB REST or SOAP Authentication through AWS string key pair, HMAC-SHA1 signature, and WS-Security NSimpleDB to the rescue Open Source @ http://code.google.com/p/nsimpledb/ C# implementation of SimpleDB data model and operations Local storage of data Simple service API Allows access to local and online data through same interface ISimpleDBService Uses VistaDB (www.vistadb.net) for persistence Uses Amazon s.net SimpleDB library 6
Connecting to (N)SimpleDB Local tuple space SimpleDB Managing domains Paged access 7
Storing items/attributes Loading items/attributes 8
Deletings items/attriubtes Queries Proprietary query syntax Limited to one domain at a time ['Firstname' = 'Peter'] INTERSECTION ['City' = 'Berlin'] Queries retrieve item names only Attributes need to be loaded separately Use multiple threads for maximum performance! 9
Query syntax definition Query ::= ItemSetTerm { "UNION" ItemSetTerm }. ItemSetTerm ::= ItemSetFactor { "INTERSECTION" ItemSetFactor }. ItemSetFactor ::= [ "NOT" ] "[" PredicateExpression "]". PredicateExpression ::= PredicateTerm { "OR" PredicateTerm }. PredicateTerm ::= PredicateFactor { "AND" PredicateFactor }. PredicateFactor ::= [ "NOT" ] PredicateComparison. PredicateComparison ::= AttributeName ComparisonOperator AttributeValue. AttributeName ::= Chars enclosed in single quotes, e.g. 'Name'. All AttributeNames in a PredicateExpression need to be the same. All quotes in AttributeName need to be properly escaped. AttributeValue ::= Chars enclosed in single quotes, e.g. '003.14'. All quotes in AttributeValue need to be properly escaped. ComparisonOperator ::= "=" "!=" ">" ">=" "<" "<=" "STARTS-WITH". Querying and loading items 10
What s missing No transaction No notifications Use SQS to compensate? No sorting Do it on the client No joins Navigational access No datatypes Alphanumeric comparisons only Pad your values for sorting/comparison No blobs Use S3 for large attribute values Use multi-value attributes Eventual consistency What s it good for? Ad hoc data storage No setup/admini/backup required No schema Scalable data storage Amazon grows for you Read-mostly data E.g. discussion forums, meta-data Due to eventual consistency and lack of tx Read-write data If eventual consistency and lack of tx is no problem Operations are idempotent Structured data 11
Pricing Source: Amazon Summary Fundamental SaaS Flexible data model Think dynamic database for dynamic languages Simple, very simple API No adminstration needed Scalable Made for concurrent access Attractively priced Crucial features missing? Watch out for tuple spaces there are more to come 12
Questions? Resources Amazon, SimpleDB, https://aws-portal.amazon.com/ Amazon, SimpleDB Dokumentation, http://developer.amazonwebservices.com/connect/entry.jspa?extern alid=1107&categoryid=146 Ralf Westphal, SimpleDB Blog Serie, http://weblogs.asp.net/ralfw/archive/tags/amazon+simpledb/default. aspx Ralf Westphal, NSimpleDB Open Source Projekt, http://code.google.com/p/nsimpledb/ 13
Über den Referenten Ralf Westphal (www.ralfw.de) ist freier Softwaretechnologievermittler. Er arbeitet als Fachautor mit mehr als 300 Publikationen, Coach/Berater und Referent auf Entwickler-Events im In- und Ausland. Schwerpunkt seiner Arbeit sind die Architektur von.net- Software und die Förderung innovativer Softwaretechnologien. Bei der Wissensvermittlung beschreitet er gerne ungewöhnliche Wege, so zum Beispiel mit den Videoserien.NET TV und dotnetpro.tv und dem Trainingsunternehmen Professional Developer College (www.prodevcollege.de). Ralf Westphal ist Microsoft Visual Developer Solution Architect MVP und war von 1998 bis 2005 einer der unabhängigen Microsoft Regional Directors für Deutschland. Email: ralfw@ralfw.de www.prodevcollege.de www.prodevcollege.de Publications Bücher.NET kompakt, Spektrum Akademischer Verlag 2002, ISBN 3827411858 In Fachzeitschriften ADO.NET Datenbankprogrammierung, Addison-Wesley 2002, ISBN 3827319978 Jetzt lerne ich ADO.NET, Markt+Technik, 2003, ISBN 3827262291 (zusammen mit Christian Weyer) Video.NET 3.0 kompakt, Spektrum Akademischer Verlag 2007, ISBN 382741458X (zusammen mit Christian Weyer) www.dotnettv.de tv.dotnetpro.de 14