Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

223
Visualizações
Optimal Approach to Api design in Google Cloud Functions?

The end desired result is a more performant system with less resource utilisation. I want to connect a sql database to cloud functions and host a set pf api's.

Here are two alternatives...

Alternative one: We host each api as a separate cloud function.

const functions = require('firebase-functions');

exports.helloFunc1 = functions.https.onRequest(function (request, response){
 response.send("Hello from Func1!");
});

exports.helloFunc2 = functions.https.onRequest(function (request, response){
 response.send("Hello from Func2!");
});

Alternative two: We host a single cloud function with internal routing.

const functions = require('firebase-functions');
const express = require('express');
const router = new express.Router();

var app = express();

var helloFunc1 = function (request, response){
 // After some DB OPS
 response.send("Hello from Func1!");
};

var helloFunc2 = function (request, response){
 // After some DB OPS
 response.send("Hello from Func2!");
};


router.get('/helloFunc1',helloFunc1);
router.get('/helloFunc2',helloFunc2);

exports.root = functions.https.onRequest(router);

Help me understand the tradeoffs between the approaches and any advantages/disadvantages in either designs.

Also please consider the database connection pooling as a part of the analysis. This wont be a determining factor if we use firebase or datastore, but for native SQL Databases, i'm assuming a lot of connections will impact performance when this is auto scaled.

EDIT #1

This is a rudimentary example, but in reality the implications maybe a lot more. Is working with a framework which provides additional functionality like ORM's and shared models, Middleware for AUTH, general convention over configuration approach a real option in a server-less environment? Because we know that these frameworks are designed to run on a always-up server. How will ORM's & frameworks in general deal with being preempted and how will it affect performance?

PS. I'm new to Node and Express.

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

Deploying Individual Functions

  • You get separate tracking of execution counts and easier log filtering in the console.
  • The functions scale independently of each other, which can be ideal if you have some endpoints with heavyweight compute/memory needs and others that don't.
  • Each function will have its own "cold start" if it has been idle, so if your endpoints have uneven usage distribution you're more likely to run into cold starts.

Deploying an Express App

  • Everything gets glommed together in the console, you're on your own for tracking individual endpoint usage and being able to filter appropriately in the logs.
  • The single function scales all together.
  • There is only a single "cold start" to worry about so anyone hitting your API is keeping all of the functions "warm" for future executions.

For the time being I'd likely recommend deploying an Express app, primarily to gain the advantage of cold start reduction. However if some of your endpoints have a very different memory/cpu profile it might make sense to separate them into their own Cloud Function (especially once it becomes easier to tweak the cpu/memory profile of functions deployed via Firebase).

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda