9
22 Comments

[Back-end] How to scale my side project to handle 100k users?

Hello hackers,

One of my side project (revealing soon) is taking off and a client is interested in migrating their 50k userbase to our platform. I'm pretty much excited as well as nervous at the same time as I'm not sure that my servers could handle such load. Any suggestions?

Also, how do you suggest migrating the data? Is it easier to expose an API to add users or is it better to transfer the users via csv file?

Once this process is complete I'd be sharing an update regarding the product and how it got good clients in a short span of time - and you can do it too. So feel free to follow me on IH or twitter for the updates. Until then, looking forward to your suggestions.

on July 29, 2020
  1. 2

    @prasanna, based on the comments about architecture (nodejs, mongodb, Digital Ocean)... here’s what I’d suggest you have covered:

    • put a load balancer in front of your servers so you can scale horizontally with demand
    • migrate your DB to Mongo Atlas... last thing you want is to manage DB crashes, scaling, and backups
    • serve static assets from a CDN designed to handle scale (Netlify, Cloudflare, AWS CloudFront)

    That should give you scalability on demand.

  2. 2

    Depends, on lots. But if your APIs are heavy on 'read' requests you can just cache those. But make sure to expire that cache correctly, when that should be depends on your application.

    If you need any help feel free to email me.

    1. 1

      Thanks for offering help mate, you rock! I really appreciate your help but I'll try to implement redis and minimize db queries for now. Will ping you if I don't succeed :)

  3. 2

    I've worked for a number of banks and never underestimate the benefits of transferring a CSV.

    You can run the import multiple times, and at your own pace, sorting out any issues that pop-up while doing so.

    It's a lot easier than going back and forth with your client asking them to retry their API requests that failed because of a data issue or a rate limit.

  4. 2

    Hi, really hard to say without knowing your app.

    But some general advice is make sure you have pagination on any list screens and stuff.
    I'd also favour csv/json import over API if it makes sense for what your model. Those import features will be easier for more customers to use and can be re-used for bulk updates.

  5. 2

    Are you doing any blocking operations? Are your services compute heavy? Perhaps going with a micro service architecture might be a solution. It all depends on the problem and what is causing it.

    1. 1

      Yup - I'm making a lot of database IO operations. That could probably be the bogging down the event queue. I'm considering an option to integrate Redis - hopefully that'll solve the problem.

  6. 2

    What scaling you need depends on the expected usage pattern. Is the usage throughout the day, only during work hours or spikes at particular times (e.g. lunchtime)?

    I would personally not worry about scaling too much since you don't know the bottle necks just yet. (EDIT: assuming you don't know them - if you know them, that's great)

    What will make your life easier to make sure you have the capability to throw money at the problem. Scale your servers horizontally (i.e. use a load balancer) and your database vertically (just get a bigger size). Lastly, have some kind of monitoring on the basics (CPU, memory) logged somewhere.

    Also does the client plan to pull the switch at once or migrate users over time? It might be easier to ask if they can stagger adoption.

    Best case scenario is that nothing breaks and your current setup is fine. Worst case, you eat some upfront costs to scale things quickly up using money (with a little bit of downtime) and you get to discover where your bottlenecks are (this is where logging comes in).

    Congrats on the success!

    1. 1

      Yeah, nothing breaks in the code. It's just that my server takes too long to respond when there are over 100 requests/second

      1. 2

        Well, 100 requests/second is quite a lot. If you have 50k users that interact with your website, say, 5 times a day and each one triggers 10 requests, we are talking on average, 29 requests/second. Of course it is likely that requests will not be smeared out over the entire day, but there will be usage peaks. How steep they'll be is up to you to predict.

        1. 1

          Yeah. I'm considerate of that peak time as I don't wanna put a bad impression on my client. I'm planning use redis to reduce database queries - hopefully it'll help serve more requests.

  7. 2

    You should stress test your setup. If you say 'you don't know' it means perhaps there's nothing to worry about. Once you know, you can describe your scaling problem better. Caching smartly, buying a bigger server, load balancing, moving DB, going serveless...

    For migrating, do whatever will be quicker for you that's acceptable to your user. I, personally, wouldn't feel comfortable sharing plain text files of 50k customers if they include sensitive data.

    1. 1

      True that. Gotta figure out a way then

  8. 2

    It really depends on the bottleneck. Are you sure you can’t handle the load? Is the db the problem? Number of concurrent users? Number of users period?

    Splitting the logic apart into something that can scale could be challenging. Sounds like you need to refactor so that more hardware makes more users possible. But any other deets would tell us more

    1. 1

      The problem is number of concurrent users. The CPU usage is under 20% for 100req/s and the memory usage is under 25% but the API takes too long to respond. Many API calls gets disconnected (ECONNRESET) after waiting for over 30s.

      I am implementing redis cache, but I am not sure why it's taking long time to respond even when the CPU is not under load and there's plenty memory left

  9. 2

    Scaling , first step is to put the database on a different server. For 100 k users this may be ok. If the load is still too much shard the database. On code side find the busiest sections and put those on multiple servers with a load balancer.

  10. 2

    Have you considered writing a load test?

    Then the next step is to monitor which resource is the bottleneck, optimize, repeat.

    Good luck!

  11. 2

    Where is your site hosted? Scaling up on a service like Netlify for example is easy but will just cost you more. Scaling up on AWS is a it trickier depending on your setup but adding a load balancer with a couple beefy servers there would probably cover you.

    As far as importing users, one option is to build yourself an admin interface that uses an internal API. Then you can add an import users from CSV interface you will be able to use.

    1. 1

      Thanks for the suggestions. I am currently using DigitalOcean droplets and the API is running on NodeJs & mongodb. I was considering a transition to serverless but I am a bit scared of getting unexpected huge bills.

      1. 1

        This comment was deleted 6 years ago

  12. 1

    Hey Prasanna, It depends on how you're storing your data today and where are you planning to move it. Maybe you could just scale up your server as a quickfix and work in a better architecture in the meantime.

    I'm running GetAdvice (https://getadvice.github.io), you could schedule a free one-to-one session call with one of our volunteers to help you analyze the problem and design a solution. The project was created with this type of uses cases in mind so feel free to check it out.

    My profile: https://getadvice.github.io/adriano.galello.html

  13. 0

    Hi,

    If your target is a more robust/HA infrastructure on AWS or GCP we can maybe assit you. We are cloud experts offering an affordable and more approachable cloud consultancy. We designed several infrastructure for our clients that are flexible, elastic and so on and operated loads of cloud migrations. We would need more information about your existing setup to figure out what would be the best option. Send us a mail at info@cloudbuddies.io if you are interested :)

  14. 0

    This comment was deleted 5 years ago

  15. 3

    This comment was deleted 6 years ago

    1. 1

      Totally! Currently the nodejs servers and mongodb server is hosted on DigitalOcean. I think too many database calls are clogging up the event queue - causing delays in execution. I'm planning to use redis, so that I could help save quite a lot of database requests.

      But apart from that, appreciate your comment mate. It helps :)