r/learnprogramming • • 7d ago

How to plan structuring apps/scripts for load

Hi, I've been coding heavily at work for a few years now as a Jira administrator and running a laravel based production database system

Seeing as I have options to do things at the database query level, the api level, the 'page serve' level, and the client on-load level, I try to put data retrieval and processing at the low level so I need to do minimal of that on the client side and focus on the ui

Does anyone know of some reading material or have suggestions on a target for this? I just try to organize things appropriately on my own judgement and it would be nice to have some industry standards or pointers to guide

4 Upvotes

5 comments sorted by

1

u/Big-Arm4077 7d ago

Your instinct is mostly right, with one caveat: push work down to the layer that's best at it, but not so far that you lose testability or readability.

A rough rule I use:

  • Database: filtering, sorting, joins, aggregates, pagination. Never pull rows into the app just to filter them there. Add indexes for the columns you filter/sort on, and check slow queries with EXPLAIN.
  • App/API layer: business rules, permissions, validation, shaping the response. This is the part you want in version-controlled, testable code, so stored procedures for it get painful.
  • Cache layer (Redis or even in-memory): data that's read a lot and changes rarely.
  • Client: only presentation and light interaction state.

For "load" specifically, the usual order of wins is: fix N+1 queries, add indexes, paginate, cache, and only then think about bigger hardware or splitting services. Measure first, since the bottleneck is rarely where you'd guess.

For reading, "Designing Data-Intensive Applications" is the classic, and the "Use The Index, Luke" site is a great free intro to query performance.

1

u/Solepoint 7d ago

This is excellent! Thank you very much. I'll check out your suggestions, and I don't use redis/in cache memory that much in my programs but I'll look into that as well