StockideasHQ

This is how I used mongodb on my website

By: ssmlee04 Community Lead :))   💬 574   
   Nov 29, 2022

I remember years ago when I was learning how to create websites, the first thing I used to start a local webserver and webpage was xampp or LAMP stack (php, Apache, MySQL,.. etc). With those stacks you can type a few commands in your terminal to have a website running in no time. As time goes by I had more exposure to different frameworks like MEAN stack (mongodb, Angular, ...etc) or Meteor and I get to learn about the all kinds of technologies and about their strength and weaknesses. But regardless of stacks you would always be in a situation when you need some sort of persistent storage to store your data. And it turns out mongodb would very often find its way into most of my development workflows and become part of the project.

https://i.stack.imgur.com/wJSSX.jpg

So, what’s special about mongodb? Not much. It's just a database that works. It's just so well-known in open-source and is relatively fast to read and write, to scale, to deploy and maintain when compared to many other database technologies. If you can find developers who know how to write a couple of lines of code and click on a few buttons to deploy a small mongodb cluster in 5 minutes, it would be fairly easy for companies to onboard engineers and create applications on them and go from there. And that suits my projects really really well.

Imagine with a couple of lines of code in node.js you can create a table and start to talk to your database.

var mongoose = require('mongoose');
var Schema = mongoose.Schema;

var UserSchema = new Schema({
  username: {
    type: String,
  },
});

const User = mongoose.model('User', UserSchema);
const user = await User.findOne({ username: "ssmlee04" });

This is very similar to what the actual production code would look like to create a user db and talk to it. This is pretty cool isn't it?

To start some small mongodb database you can simply spin up virtual machines on AWS ($amzn) or digitalocean ($docn), and with a bit of configuration you would have a small db cluster running in no time. I also have scripts to backup the db to S3 and restore the database. And occasionally I would see the database grow to disk space limit or crash so that I would need to ssh into the machine to do something about it. It's doable but it's not worry-free. And for a period of time I had this constant fear that my database would go away and I would lost the data forever when I am asleep. And then I discovered there are fully-managed solutions such as Mongodb Atlas.

So there's a company called MongoDB Inc that takes this open-source mongodb and bundles it into a cloud service called MongoDB Atlas. They're a public company traded under ticker symbol mdb by the way. Atlas is a cloud database service that helps you deal with the complexities of running a database. Without Atlas, you would be hosting VMs, deal with the maintenance overheads yourself. But this is really not good time spent for most companies when it costs so much to hire a dev in 2022. Imagine with a few extra bucks a month you wouldn't need developers to maintain most of the complexities of the database and can focus on developing your applications that actually matters to your business. Keep in mind, for faang, it costs like 200k-400k a year easily to hire a dev, so it is pretty justifiable to spend a few million dollars a year to run a few databases at their scale if a cloud service like $mdb satisfies your needs.

Starting a database cluster in Atlas is free and it's as easy as a mouse click.

https://i.imgur.com/ixDXNNC.png

https://i.imgur.com/PtuUCQY.png

https://i.imgur.com/W7Xt9OL.png

With just a few extra clicks, you can integrate services like datadog ($ddog) and pagerduty ($pd) for basic monitoring and on-call notifications. In a matter of minutes, you can have a database that is well-maintained, configured, and in the same state as it was when it was managed by a team of db admins.

Atlas charges you based on compute and storage. Compute means how fast your database can process requests. Storage is about how much disk space that's allocated to your db and how often you can do your backups. This is actually not a bad idea, because for most companies that's growing and uses Atlas they would have more applications running every quarter. This means your data, number of databases and collections, your size and duration of backups would only go up normally. Can you go back to hosting VMs yourself and do bare-metal mongodb? You can't because it wouldn't make much sense to justify hiring extra engineers to do the heavy-lifting of running a database. That just won't work anymore, at least not without scale.

There's also no reason you cannot use other db technologies like ElasticSearch or Cassandra. It's just databases is not something you can switch easily if you already have a lot of existing applications running with mongodb. When you have an industry of people who know how mongodb works, have products running based on it, switching to something else can be costly. In addition, if you decide to migrate away from it, you'll have to worry about issues like consistency or loss of data. So unless mongodb becomes a bottleneck of your application it’s usually difficult to justify moving away from it.

$mdb


PD - PagerDuty, Inc  51.73% since post
MDB - MongoDB, Inc  51.48% since post
DOCN - DigitalOcean  27.64% since post
AMZN - Amazon.com  6.55% since post
DDOG - Datadog, Inc  -7.42% since post
Reply
The Stockguy
  
452570
Member since: 2019-03-03
Followers: 3
Posts: 574
Replies: 229

Hi, I'm Shih-Min. I am a software engineer that deals with highly-scalable, distributed and fault-tolerant systems.
SaaS
Nasdaq