API node service and MongoDB service - node.js

We currently have an API service that simply fulfills requests for data in a mongoDB database hosted in Atlas. We have a separate node service that the API service calls to actually get/put data in the mongoDB database. I'm wondering if the API service should not just access the mongoDB database directly. It seems simpler, less services to maintain, scale, potential issues with to simply have the API service access the mongoDB database directly. I'd appreciate anyone's thoughts on this. Thanks.

If your API service is secure, I see no need for the node service step. I have an API that has read/write access to my MongoDB Atlas instance and it works just fine. I also use monitoring such as New Relic and I'd hate to have to include another service in that for no reason. I'd say, if you can track the latency etc of queries with the node service and without, you will probably benefit from removing that step.

Related

What is the recommended way to use MongoDB with a NodeJS application deployed on Elastic Beanstalk?

I am currently building a web app which needs a database to store user info. The startup I'm working for wants to deploy it on Elastic Beanstalk. I am just getting started with all the cloud stuff and am completely at a loss.
Should I create a MongoDB Atlas cluster? Will it be able to connect to my app hosted on EB? Will I need to upgrade my plan on AWS to be able to connect to a database? Can it be integrated with DynamoDB? If yes, is DynamoDB significantly costlier?
I don't have answers to any of the above questions and am just honestly looking for a roadmap on what to do. I went through numerous articles and videos but still can't arrive at a solution. Any help will be much appreciated.
Should I create a MongoDB Atlas cluster?
That is one possible solution. You could also look at Amazon's Document DB service, which is MongoDB compatible.
Will it be able to connect to my app hosted on EB?
There is nothing preventing you from connecting to a MongoDB Atlas cluster from EB.
Will I need to upgrade my plan on AWS to be able to connect to a
database?
No
Can it be integrated with DynamoDB?
DynamoDB is a completely different database system, that shares almost nothing in common with MongoDB other than the fact that neither of them use SQL. If your application already uses MongoDB, then converting it to DynamoDB could be a large lift.
If yes, is DynamoDB significantly costlier?
In general, DynamoDB would be significantly cheaper than MongoDB, because DynamoDB is a "serverless" offering that charges based on your usage patterns, while MongoDB would include charges for a server running 24/7.

Azure - Cosmos DB integration with API Apps

Is there any integration between CosmosDB and Api Apps? I'm kinda new in Azure and I don't really understand which is the best approach.
My problem is that I am working on an IoT Project which gets data from the IoT Hub, passes it to a Function that sends it to the CosmosDB which then would need to be consumed by a Frontend. A pretty standard case.
I would usually create a backend to place between the database and the frontend but I really can't understand which is the best way to do it in Azure. Should I use the Api Apps or the integrated SQL Apis that are provided with CosmosDB? Are the Api Apps comparable to "containers" for my backend or do they have any other use other than keeping my code in a cloud machine?
Thanks a lot in advance!
You can't (well, shouldn't) have your frontend to directly call the database so you need a middle layer of some sort.
Creating an API could be one of the ways you go about it but based on your use-case, I would go with an HTTP Trigger Azure Function which would be the API that exposes the data.
You can then use the Cosmos DB Input Binding to retrieve the object you want to return and simply return the JSON of it.

Deploy NodeJS/MongoDB application. Where and how?

I’ve finished working on my node application which provide a series of APIs endpoint for a mobile application. I’ve made it with node and mongodb as db. Now I’ve reached the point where I should pick the right deployment environment.
Initially I’ll make a private beta but I need to choose a service I can scale easily (I’m not a devop) with the right price balance.
My initial choice is amazon aws (elastic beanstalk?). What’s about the db? I’ve not used dynamodb in order to be more service agnostic but now I don’t know how to create a reliable db infrastructure. Any suggestion to deploy both app and dB in order to make easy scaling in case it will become necessary?

Can DocumentDB successfully act as entire mobile app backend with data and logic

DocumentDB on Azure can besides the data hold JavaScript app logic in stored procedures, trigger and user defined functions.
If the app logic is computationally fairly simple (or even if it is not) would it then be a usable solution to have the entire backend in the DocumentDB instance and then have the client apps connecting directly via the DocumentDB REST interface? Or am I missing something in terms of security performance here?
Yes, there are scenarios where you don't need a middle tier and directly perform queries from your javascript client to the DocumentDB.
However, you don't want to expose a Master key to the client, instead you wan't to work with Resource tokens, thus you need a small middle tier service that issue a timebound token.
Also see Securing access to DocumentDB data.

Does azure provide a REST API for databases? Or do I have to write my own?

We need to write a very quick web application hosted on azure. Backed by sql database. I kind of hoping we don't need to start creating a full webapi project with visual studio - routing, EF etc. It would be great if azure could provide a rest api for my database.
I think dreamfactory might be doing this. But I tried to use their free trial but it didn't allow sql server unless you sign up.
I would have thought this would be a standard requirement for small apps.
If what you mean by "rest API for my database" is the possibility to use JSON documents against it, then you should definitely look at documentDB
It provides:
JSON based document access and indexing,
Low latency & scaling,
Support for mongoDB driver
To complement this answer, DocumentDB is also capable to be accessed using client-side JS as shown here but only with specific Windows 8/10 sdks
So bottom line is: DocumentDB can't be directly accessed.
If DocumentDB serves your purpose and CORS is the only issue then you can use Azure API Management as a gateway between ui/js and back-end DocDB. CORS can be enabled at APIM with a policy expression.
https://azure.microsoft.com/en-us/services/api-management/
https://msdn.microsoft.com/library/azure/7689d277-8abe-472a-a78c-e6d4bd43455d#CORS

Resources