The document provides an overview of Amazon SimpleDB, including how it can be used with Ruby on Rails. SimpleDB is a non-RDBMS database service that allows flexible storage and querying of data without a predefined schema. The document outlines SimpleDB concepts like domains, items, and attributes, and how to use the AWS SDB proxy plugin to interface SimpleDB with Rails models and perform CRUD operations.
2. Amazon SimpleDB
● Database web service advertised as:
● Simple, Flexible, Scalable, Fast, Reliable, Inexpensive
● No RDBMS: no SQL, no joins, no schema,
no referential integrity, no transactions
● Ability to store, process and query data
sets
http://webonrails.com
3. Amazon SimpleDB
● HTTP-Interface
● Pricing: Similar to other AWS
http://webonrails.com
5. Let, have a look
at
Amazon SimpleDB
Common Terms
http://webonrails.com
6. Amazon SimpleDB Common
Terms
● Domain:
storage container ~ table
● Item:
~ table rows accessed by ID ~ primary key
● Attribute:
~ table columns; every item may have a different
set of upto 256 attributes
http://webonrails.com
7. Amazon SimpleDB Common
Terms
● Value:
each Attribute may havemultiple Values, always
varchar(1024)[]
http://webonrails.com
8. SimpleDB
Domain A
Attributes
Items
Values (multiple)
http://webonrails.com
10. Amazon SimpleDB API
● Domain level:
● CREATE, LIST, DELETE
● Item level:
● GET, PUT, DELETE attributes with values
● QUERY for unordered item IDs by
attribute values within one domain
● Beware: Eventual Consistency Approach!
http://webonrails.com
11. Benefits over traditional databases
● No need to pre-define data types
● 'Size' can be 9 or XL or 1.5
● Add attributes anytime
● Attributes specifically for some items
● Index all data
http://webonrails.com
12. API Summary
● CreateDomain — Create a domain(100).
● DeleteDomain — Delete a domain.
● ListDomains — List all domains.
● DomainMetadata — Retrieve information
about the domain.
http://webonrails.com
13. API Summary
● PutAttributes — Add or update an item and
its attributes, or add attribute-value pairs to
items that exist already.
● GetAttributes — Retrieve an item and all or
a subset of its attributes and values.
● DeleteAttributes — Delete an item, an
attribute, or an attribute value.
http://webonrails.com
14. API Summary
● Query — Query the dataset using a query
expression which specifies value tests on
one or more attributes.
● Supported value tests are:
=, !=, <, > <=, >=, starts-with.
[“price” < “12.00”] INTERSECTION [“color” = “green”].
● Order results using the SORT operator
http://webonrails.com
15. API Summary
● QueryWithAttributes — Enables developers
to retrieve all or a subset of the information
associated with items returned as a
response to a particular query.
http://webonrails.com
16. SimpleDB vs S3
S3 SimpleDB
● Stores raw data ● Stores indexed data
● Uses higher dense ● Uses less dense
storage drives storage drives
http://webonrails.com
17. SimpleDB Limits (Cont...)
● Domain size 10 GB per domain
● Domain size 250,000,000 attribute name-
value pairs
● Domain name 3-255 characters
● Domains per account 100
● Attribute name-value pairs/item 256
● Attribute name length 1024 bytes
● Attribute value length 1024 bytes
● Item name length 1024 bytes
● All UTF-8 characters that are valid in XML documents are
allowed in name/value.
http://webonrails.com
18. SimpleDB Limits
● Attributes per PutAttributes operation 100
● Maximum items in query response 250
● Maximum query execution time 5 seconds
● Maximum comparisons per predicate 10
● Maximum predicates per query 10
expression
● Maximum response size for 1MB
QueryWithAttributes
http://webonrails.com
19. Working with Numerical Data
● SimpleDB is a schema-less data store
● Everything is stored as a UTF-8 string value
http://webonrails.com
20. Working with Numerical Data
● Ensure that every number is positive
http://webonrails.com
21. Working with Numerical Data
● Ensure that every number is positive
What about Negative
Numbers?
http://webonrails.com
22. Negative Numbers Offsets
● Choose an offset
● That should be arger than the smallest
expected negative number in your data set
● Ex:
● if the smallest expected number in your data set is -12,
choosing offset = 100 might be safe
http://webonrails.com
23. Negative Numbers Offsets
The following is a sample original data set.
14.58, -12.7, 20, 65, -23
If you apply an offset of 100 the following is the resulting
data set:
114.58, 87.3, 120, 165, 77
http://webonrails.com
24. Zero Padding
● Since simpleDB uses lexicographical
comparisons “10” comes before “2”
● If we zero pad the numbers to five digits,
quot;00002quot; comes before quot;00010quot;
http://webonrails.com
25. Zero Padding
● Since simpleDB uses lexicographical
comparisons “10” comes before “2”
● If we zero pad the numbers to five digits,
quot;00002quot; comes before quot;00010quot;
http://webonrails.com
34. Using AWS SDB Proxy Plugin
● Create demo ActiveResource model
class Post < ActiveResource::Base
self.site = quot;http://localhost:8888quot;
self.prefix = quot;/MyDataStore/quot;
end
http://webonrails.com
35. Lets try at script/console
>> Article.create(:title => quot;This is my First articlequot;)
=> #<Article:0xb7005d04 @attributes={quot;updated_atquot;=>Sat Dec 13
15:53:30 UTC 2008, quot;titlequot;=>quot;This is my First articlequot;,
quot;idquot;=>601834...98, quot;created_atquot;=>Sat Dec 13 15:53:30 UTC 2008},
@prefix_options={}>
>> a = Article.create(:title => quot;This is my Second articlequot;)
=> #<Article:0xb6fe1f08 @attributes={quot;updated_atquot;=>Sat Dec 13
15:53:52 UTC 2008, quot;titlequot;=>quot;This is my Second articlequot;,
quot;idquot;=>112...9, quot;created_atquot;=>Sat Dec 13 15:53:52 UTC 2008},
@prefix_options={}>
>> a.body = quot;Nothingquot;
>> a.save
=> true
http://webonrails.com
36. Lets try at script/console
>> Article.find(:all).size
=> 2
>> Article.find(:all, :from => :query, :params => quot;['title' starts-with 'This
is' ]quot;)
=> [#<Article:0xb6f73080 @attributes={quot;updated_atquot;=>Sat Dec 13
15:53:30 UTC 2008, quot;titlequot;=>quot;This is my First articlequot;, quot;idquot;=>60...98,
quot;created_atquot;=>Sat Dec 13 15:53:30 UTC 2008},
@prefix_options={}>, #<Article:0xb6f7306c
@attributes={quot;updated_atquot;=>Sat Dec 13 15:54:14 UTC 2008,
quot;bodyquot;=>quot;Nothingquot;, quot;titlequot;=>quot;This is my Second articlequot;,
quot;idquot;=>11...79, quot;created_atquot;=>Sat Dec 13 15:53:52 UTC 2008},
@prefix_options={}>]
http://webonrails.com