This is actually my first post on SO, and I'm somewhat new to back-end programming (learning Ruby currently, but I'm familiar with front end stuff) so please bare with me if my questions seem quite noobish. I have a great interest in learning/getting a grip on Ruby and Rails, and so I figured this would be a great place to ask questions when I'm stumped.
While learning Ruby, I've been coming up with few questions which I need clarified. I've looked up these questions on Google but problem is I just need someone to explain the answers to me in a straightforward, laymen fashion (with everyday examples included). I mostly end up reading series of text on the internet that just talk about theories. I'm not disregarding the need to learn those theories as I realize I'll one day perhaps need to learn em to get a better grip on the subject, but for now, I just wanna start small, and build my way up to more complicated things.
So, here they are:
1) So essentially what are Databases? People say it stores data (duh) but what sorts of data are we speaking of? Like, if I for example were to build Facebook for the first time, what sort of information would my databases store? User log-in info and such?
2) Speaking of databases, what are the "best" ones to use? I know it really is a matter of preference, but I'm mostly concerned with super speed, efficiency, reliability, and simplicity of use. What is one you would personally recommend?
3) Heroku is a rails-friendly server that allows you to deploy rails app without having to worry about server administration monkey work -- right?
Super Thanks to everyone who shows me the light by answering my questions. I'll have more in the future I'm sure :)
1) Databases are essentially a means to store data from the app/user in an organized / structured way according to what type of data is being stored. They also provide a way to create relationships between all the stored data and make it easy to query later on.
For example, finding a user's photos is extremely easy even though you store the user's data in one table and the photo's meta data in another table. Using Ruby on Rails, it can be as easy as saying the_photos = @user.photos and you're done. Behind the scenes, Rails generates all the SQL code necessary to tell the database, "Hey, go find a user with this ID and then go find me all photos associated with that user ID in the Photo table," without you having to know any SQL at all.
In ActiveRecord (which is what Rails uses by default), you have these data types:
:primary_key :string :text :integer :float :decimal :datetime :timestamp :time :date :binary :boolean
Typically, a database is split up into multiple tables and you organize your tables according to what type of information they are saving. So you might have a Comment table, User table, and Photo table, all of which store different types of data about those items. So if you were saving a comment, you might use a :text field to store the comment, an :integer field to store the user's ID who created the comment and a :timestamp field to record what time the comment was made.
2) If you're working with Rails and considering using Heroku, then you'll likely use SQLite for local development (since it's easy) and then PostgreSQL by default on Heroku (it's a very mature and proven db). There are other database types though such as MongoDB so it really depends on your need.
3) Correct, Heroku takes care of a lot of the server management for you. However, you'll still need to worry about scaling your servers up/down efficiently and I would recomment http://www.hirefireapp.com for that since it works seamlessly with Heroku.
4) Actually, most of the load time is spent in the database digging out all the data required to render the page, especially if you have complex relationships like friends of friends (such as with the Facebook example). That's why people use memcached to cache the database query results for future use so the load time drastically improves.
Extra help... if you're learning Ruby on Rails, this is by far the easiest to understand tutorial and the one that everyone recommends: http://ruby.railstutorial.org/
After that, the Ruby on Rails dev team has put together some amazingly helpful tutorials here: http://guides.rubyonrails.org/
Best of luck!
1) It will store all your photos, all your comments, all your favorites books, who are your friends, who is your girlfriend... Well in short all your life. Afraid? Me too
2) That's a very deep subject. I just saw that a new book by PragProg is announced http://pragprog.com/book/rwdata/seven-databases-in-seven-weeks. It covers 7 different type of databases. Short answer, there is no best db. Start with the rails default Sqlite3.
4) I think that the future is on the front-end, rich clients and JS. What gives the feeling slowiness are the synchronous requests between the browser and the server.