I'm building my first PHP web app with AngularJS as the front end and utilizing Slim to create a REST-like API for the web app to interface with. I'm finding that the majority of my code I'm writing is SQL, there is very little PHP logic in the backend except for sessions and input validation.

Each endpoint might have 1-2 unique queries it uses to get the data it returns to the client. A few endpoints utilize 3-5 queries for some complex version management, historical data modifications, and validation bits.

Is it normal for a web app to have a really SQL heavy backend? Are there best practices for this sort of thing? I'm about 70% SQL 30% PHP right now.

  • As Michael said, understanding of the problem and design is required. I'd guess that ten years ago you'd have had a dumb HTML client, full-featured services and some DB stuff. With current tech you've moved the smarts to the browser which leaves the services thin. Be aware that the DB can't scale the way a services layer could, so don't put more there than you have to. Ability to cache & work off-line will be affected by design choices, too. Commented Oct 11, 2016 at 23:28

1 Answer 1


Without seeing designs, code and a good understanding of the domain, I don't think anyone could legitimately argue one way or another. A code base that is 70% SQL isn't typical, but that doesn't necessarily mean its wrong. I've maintained some systems that, for better or worse, had the whole DAL in the database - the back-end code simply called stored procedures.

The biggest potential red flag is that SQL tends to be hard to read for complex data manipulations that do not readily fit into a declarative model. If the code is difficult to read, that would be the first sign that something has to give so long as performance changes remain within acceptable boundaries.

Stated more generically, I wouldn't worry about it if you are using SQL for the things at which SQL excels - declarative data retrieval and manipulation. If you are pushing SQL to its limits, it might be time to look at alternative approaches.

  • Gotcha. A lot of the actual manipulation is done on the clients end, I've offloaded a lot of the processing to the client. I only do very minor modifications to data structures on the server side stringify it and serve it to the client where it gets manipulated to fit in. I'm sure this contributes to the odd ratio. Commented Oct 11, 2016 at 21:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.