YouTube

Got a YouTube account?

New: enable viewer-created translations and captions on your YouTube channel!

English subtitles

← Part 2 - Web Development

Get Embed Code
5 Languages

Showing Revision 5 created 05/25/2016 by Udacity Robot.

  1. With this office hours we had a lot of questions about MySQL and PostgreSQL
  2. and why you prefer Postgres to MySQL, why other people MySQL a lot of the time.
  3. If you could answer some of those, it'd be great.
  4. Yes, yes. We'll start with the first question, which is why I prefer Postgres over MySQL.
  5. This is a two-part answer.
  6. Back in 2005 when we started Reddit, I was basically where you are now,
  7. which is just learning how web apps work.
  8. I was trying to install all this stuff on my computer, and I was trying to install MySQL and Postgres,
  9. and MySQL wouldn't compile on my Mac and Postgres would. >>That's a good reason.
  10. I mean, actually to be fair, it says a lot about a project.
  11. Like if it builds on my Mac it'll probably build just about anywhere,
  12. because at the time OSX was still fairly new.
  13. That's how we started with Postgres.
  14. MySQL at the time was still very popular--far more popular than Postgres,
  15. but it had a reputation for being a little lossy with data.
  16. This may be the right word--a little inconsistent.
  17. Postgres--the documentation was better, they would sacrifice functionality over stability
  18. and consistency and adherence to kind of the SQL standard.
  19. Some queries that we did on Reddit that kind of pushed the limits of these databases
  20. ran much, much faster in Postgres than in MySQL, so I've just been loyal ever since.
  21. These days feature-for-feature they're basically the same.
  22. MySQL is not nearly so cavalier with your data
  23. and a lot of people use MySQL.
  24. At this point, whichever you prefer.
  25. Maybe go back to whichever compiles easier on your computer is
  26. a perfectly acceptable reason these days, I think.
  27. We also had some questions about other types of databases,
  28. why NoSQL databases were popular, why a lot of companies are moving to that.
  29. You mentioned that Facebook uses MySQL, I believe,
  30. and we had some questions about them using NoSQL as well.
  31. Okay, sure. NoSQL is basically a reaction to the difficulties of developing with SQL databases.
  32. One of the challenges of SQL databases is you have define your tables ahead of time.
  33. You have to know your coms are going to be. You have to know what the type are.
  34. When you're writing web software, one of the advantages of writing web software
  35. is you don't have to think everything through in advance.
  36. You can get something working. You can put it online. You can see how users react to it.
  37. You can kind of iterate from there--add new features, take features away--whatever you want to do.
  38. The challenge is when you have databases and a large amount of data,
  39. you have to sometimes add a new column or add a new index or add a bunch of new datatypes.
  40. When you have a database in production that has thousands or millions of users,
  41. this can be really painful.
  42. These NoSQL databases--generally, they try to solve that problem.
  43. Another way to describe them would be schema-less databases.
  44. The databases don't have a schema.
  45. That is they don't have a formal description of columns and datatypes, and it's neat.
  46. On Reddit, we kind of built our own kind of schema-less system on top of Postgres.
  47. We actually do the same thing again at Hipmunk.
  48. It's a nice way of working.
  49. The challenge right now with a lot of these schema-less databases is they're not very good.
  50. They're brand new technology. Databases are really hard.
  51. They have stability problems. Documentation is lacking.
  52. Not very many of them are used in the wild in production,
  53. so you don't have good support and people to lean on and that sort of thing.
  54. In my opinion it's still wise, especially when it comes to data,
  55. especially if you care about your data, to stick with something that's proven, that works,
  56. that you know how to scale.
  57. Everybody has worked with Postgres and MySQL for a long time now,
  58. so those things work very, very well.
  59. Now, as for Facebook--I don't work at Facebook, so I'm not an authority on the subject--
  60. but I know they use a lot of MySQL.
  61. They've actually made a lot of improvements to MySQL.
  62. They also wrote their own NoSQL system, called Cassandra,
  63. which my understanding--although I don't know for sure--is they don't actually use anymore.
  64. Reddit uses Cassandra, incidentally. They started using that after I left, however.
  65. I can't say with a clear conscious that I condone that decision,
  66. but apparently it's working for them in production.
  67. Your mileage may vary. Personally, I'm happy with Postgres.
  68. I know how to scale it these days, and you can get away with kind of schema-less
  69. behaviors in Postgres by just storing one column that's like a big wad of JSON, for example.
  70. That actually works really well, depending on what problems you're solving.
  71. Anyway, that's a long answer to a simple question, but that's my opinion. >>Great.