3 ms·
> This is not true, and not what we talk about when we say it's almost always the db. It depends who's talking and what they are talking about. If we're talki
by dorfsmay 7y ago
> This is not true, and not what we talk about when we say it's almost always the db.
It depends who's talking and what they are talking about.
If we're talking about fixing slow website, then sure, bad big ugly queries are one dominant issue, but not the only one. If we're talking about architecture of a greenfield project, then balancing between concurrent writes and consistency is going to be your ultimate problem, everything else can be "duplicated" (read-duplicated DB servers, caching strategies, multiple apps server, etc...).
- mattmanser 7y agoAnd who ever needs to think about that stuff? A tiny number of companies. Again, I just think you're not considering the vast majority of us here work in terms of thousands, 10s of thousands or millions of users, not the sort of scales where anything you're saying ever becomes relevant. For most of us, if you spend any time thinking about that, you're utterly wasting it. It's pointless. Greenfield or not.
- scarface74 7y agoI have no idea where the mindset comes from that only large companies have large datasets.
- bcrosby95 7y agoIn my experience, a dataset is considered large if its the largest dataset the company has ever seen. It could be 2GB and be considered "large".
- dorfsmay 7y agoReplying to mattmanser in the sibling comment since I cannot replying to it directly: It comes in faster than you think. One of the company I work for was a small company, at the time I think we were 4 or 5 including the 2 founders, they sell some specific information as a service through APIs. They charge per call, so you have to update the customer funds in their account on each API call. Yes, people can want and make lots of APIs call very fast, and in a business which charges per API call, this is a good thing, but you have to find strategies and make business decisions on how to handle accepting and replying to new API calls while maintaining their account balance.
- nostrademons 7y agoLoad the remaining customer funds into RAM, and decrement them on each API. Periodically flush the remaining balance to DB at set intervals (say every hour). If the server goes down, well, your customers got free API calls for an hour to compensate them for their trouble. With any reasonable uptime you'll save more on DB traffic than you lose in lost revenues. (BTW, the "can't reply" issue happens on HN when there's a long comment thread between just two people that's being rapidly updated. If you wait 10 minutes or so you'll be able to reply.)
- jimktrains2 7y ago> Load the remaining customer funds into RAM, and decrement them on each API. Periodically flush the remaining balance to DB at set intervals (say every hour). So you only ever have one app server? Sure, this specific issues could be handled other ways, but in general global state is hard.
- nostrademons 7y agoIf you have more than one app server load the customer funds into Redis and use atomic operations to decrement it. Serving out of RAM is going to be orders of magnitude faster than updating disk regardless of how much you spend on network overhead. If you have so many customers that they blow the RAM limit on a Redis box....well, you won't, because that's billions of customers. You can get surprisingly far on one app server (or sometimes one app server with 2 mirrors for failover). See eg. the latest TechEmpower benchmarks [1], where common Java and C++ web frameworks can serve 300k+ reqs/sec off of bare-metal hardware. The OP indicated that these API requests are basically straight queries anyway, and only need to write to update the billing information. Reads can run incredibly fast (both because they can usually be served out of cache and because they can be mirrored), so if your only bottleneck is the write, take the write out of the critical path. In general global state is hard. Don't solve general problems, solve specific ones. Atomic counters have a well-understood and highly performant solution. [1] https://www.techempower.com/benchmarks/#section=data-r17&hw=ph&test=fortune https://www.techempower.com/benchmarks/#section=data-r17&hw=...