Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does building an application in Arango Foxx offer beyond a regular node application

Tags:

arangodb

foxx

I'm learning more about ArangoDB and it's Foxx framework. But it's not clear to me what I gain by using that framework over building my own stand alone nodejs app for API/access control, logic, etc.

What does Foxx offer that a regular nodejs app wouldn't?

like image 601
Yehosef Avatar asked Feb 10 '16 10:02

Yehosef


People also ask

What is the validation library that comes bundled with Foxx?

Joi is a validation library that is used throughout Foxx to define schemas and parameter types.

What is Foxx services?

Foxx services consist of JavaScript code running in the V8 JavaScript runtime embedded inside ArangoDB. Each service is mounted in each available V8 context (the number of contexts can be adjusted in the server configuration). Incoming requests are distributed across these contexts automatically.

What is Foxx ArangoDB?

Through the Foxx Microservice Framework, ArangoDB allows application developers to write their data access and domain logic as microservices and running directly within the database with native access to in-memory data.


1 Answers

Full disclosure: I'm an ArangoDB core maintainer and part of the Foxx team.

I would recommend taking a look at the webinar I gave last year for a detailed overview of the differences between Foxx and Node and the advantages of using Foxx when you are using ArangoDB. I'll try to give a quick summary here.

If you apply ideas like the Single Responsibility Principle to your architecture, your server-side code has two responsibilities:

  1. Backend: persist and query data using the backend data storage (i.e. ArangoDB or other databases).

  2. Frontend: transform the query results into a format acceptable for the client (e.g. HTML, JSON, XML, CSV, etc).

In most conventional applications, these two responsibilities are fulfilled by the same monolithic application code base running in the same process.

However the task of interacting with the data storage usually requires writing a lot of code that is specific to the database technology. You need to write queries (e.g. using SQL, AQL, ReQL or any other technology-specific language) or use database-specific drivers.

Additionally in many non-trivial applications you need to interact with things like stored procedures which are also part of the "backend code" but live in the database. So in addition to having the application server do two different tasks (storage and rendering), half the code for one of the tasks ends up living somewhere else, often using an entirely different language.

Foxx lets you solve this problem by allowing you to move the logic we identified as the "backend" of your server-side code into ArangoDB. Not only can you hide all the nitty gritty of query languages, edges and collections behind a more application-specific API, you also eliminate the network overhead often necessary to handle requests that would cause more than a single roundtrip to the database.

For trivial applications this may mean that you can eliminate the Node server completely and access your Foxx API directly from the client. For more complicated scenarios you may want to use Node to build external micro services your Foxx service can tap into (e.g. to interface with external non-HTTP APIs). Or you just put your conventional Node app in front of ArangoDB and use Foxx to create an HTTP API that better represents your application's problem domain than the database's raw HTTP API.

It's also worth keeping in mind that structurally Foxx services aren't entirely dissimilar from Node applications. You can use NPM dependencies and split your code up into modules and it can all live in version control and be deployed from zip bundles. If you're not convinced I'd suggest giving it a try by implementing a few of your most frequent queries as Foxx endpoints and then deciding whether you want to move more of your logic over or not.

like image 166
Alan Plum Avatar answered Jan 03 '23 23:01

Alan Plum