I work in a startup where the backend is PHP laravel
My tech lead told me while node(expressJS) is faster its not production ready and the server cost is also very high which eats into the profitability and cannot handle loads similar to laravel
I have kind of enjoyed laravel since it comes with so many things baked in the framework itself. But That being said is there any truth of what he said ? . He is a not a bullshitter since he has credible experience working in startups and has really deep knowledge.
Videos
So I know since this is the laravel subreddit answers might be slightly biased but I would really appreciate unbiased opinions. I switched to node js some time ago and before switching, I was a laravel user for a year. My main reason being the faster/better performance of node js.
I know that performance doesn't matter when your project is small but my whole mindest was "what if my website suddenly becomes popular and a lot of people visit it?". My budget most of times is limited so I want a server that is fast and can handle a lot of requests pretty well. Nodejs seemed to handle that scenario better but now that I checked out laravel again, some even say that laravel octane is faster than node js. Is that true? Can I have high performance REST APIs (since I build mostly build SPAs) using octane or node will still be my best bet? Thanks
With basic get/set DB operations there isn't going to be significant time in whichever language you choose.
Choose a language based on non-performance criteria and solve specific performance problems as they arise.
As you've tag load-balancing I assume you application is already horizontally scaleable.
I built myself sql script writer like this, it's pretty fast for my project since my previous PHP Backend is too slow (in my case)
const mysqlLib = require('mysql');
const ENV = require('../configs/env').ENV;
const database = ENV.database;
const mysql = mysqlLib.createPool(database);
function executeQuery(query) {
return new Promise((resolve, reject) => {
mysql.query(query, (err, result, fields) => {
if (err) {
console.log(query);
return reject(err);
}
resolve(result);
});
});
}
function executeQueryGetFirst(query) {
return new Promise((resolve, reject) => {
mysql.query(query, (err, result, fields) => {
if (err) {
console.log(query);
return reject(err);
}
result = JSON.parse(JSON.stringify(result));
if (result.length == 0) {
resolve(null);
} else {
resolve(result[0]);
}
});
});
}
var Database = {
getById(table, id) {
var query = '';
query += 'SELECT * FROM ' + table + ' ';
query += 'WHERE Id = ' + id;
query += ' LIMIT 1';
return executeQueryGetFirst(query);
},
getAllById(table, id) {
var query = '';
query += 'SELECT * FROM ' + table + ' ';
query += 'WHERE Id = ' + id;
return executeQuery(query);
},
getByAttributes(table, attributes) {
var query = 'SELECT * FROM ' + table;
var whereQuery = '';
for (prop in attributes) {
if (whereQuery != '') {
whereQuery += ' AND ';
}
if (attributes[prop] == null) {
whereQuery += prop + ' IS NULL';
} else {
whereQuery += prop + ' = "' + attributes[prop] + '"';
}
}
query += ' WHERE ' + whereQuery;
query += ' LIMIT 1';
return executeQueryGetFirst(query);
},
getAllByAttributes(table, attributes) {
var query = 'SELECT * FROM ' + table;
var whereQuery = '';
for (prop in attributes) {
if (whereQuery != '') {
whereQuery += ' AND ';
}
if (attributes[prop] == null) {
whereQuery += prop + ' IS NULL';
} else {
whereQuery += prop + ' = "' + attributes[prop] + '"';
}
}
query += ' WHERE ' + whereQuery;
return executeQuery(query);
},
getAll(table) {
var query = 'SELECT * FROM ' + table;
return executeQuery(query);
},
add(table, attributes) {
var insertName = '(Id';
var insertData = '(NULL';
for (prop in attributes) {
var value = attributes[prop];
if (value != null) {
value = '"' + value + '"';
}
insertName += ', ' + prop;
insertData += ', ' + value;
}
insertName += ')';
insertData += ')';
var query = 'INSERT INTO ' + table + ' ' + insertName + ' VALUES ' + insertData;
return executeQuery(query);
},
updateByID(table, id, attributes) {
var query = 'UPDATE ' + table;
var setQuery = '';
for (prop in attributes) {
if (setQuery != '') {
setQuery += ', ';
}
setQuery += prop + ' = "' + attributes[prop] + '"';
}
query += ' SET ' + setQuery + ' WHERE Id = ' + id;
return executeQuery(query);
},
updateByAttributes(table, findAttributes, attributes) {
var query = 'UPDATE ' + table;
var setQuery = '';
var whereQuery = '';
for (prop in attributes) {
if (setQuery != '') {
setQuery += ', ';
}
setQuery += prop + ' = "' + attributes[prop] + '"';
}
for (prop in findAttributes) {
if (whereQuery != '') {
whereQuery += ', ';
}
whereQuery += prop + ' = "' + findAttributes[prop] + '"';
}
query += ' SET ' + setQuery + ' WHERE ' + whereQuery;
return executeQuery(query);
},
deleteById(table, id) {
var query = 'DELETE FROM ' + table + ' WHERE Id = ' + id;
return executeQuery(query);
},
deleteByAttributes(table, attributes) {
var query = 'DELETE FROM ' + table;
var whereQuery = '';
for (prop in attributes) {
if (whereQuery != '') {
whereQuery += ' AND ';
}
whereQuery += prop + ' = "' + attributes[prop] + '"';
}
query += ' WHERE ' + whereQuery;
return executeQuery(query);
}
}
Database.executeQuery = executeQuery;
Database.executeQueryGetFirst = executeQueryGetFirst;
exports.Database = Database;
Env config
var ENV = {
isDev: true,
database: {
connectionLimit: 10,
host: 'localhost',
user: 'root',
password: '',
database: 'your_database'
}
}
exports.ENV = ENV;
exports.ENV.port = ENV.isDev ? 15001 : 8887;