!CHAPTER Foxx Foxx is a framework that allows you to write data-centric microservices. It is executed directly inside of ArangoDB and grants you raw access to your data. With the framework you can embed complex queries and data-focused business logic into your database. Using Foxx will give you several benefits above writing the code in separate applications. First of all it yields performance benefits, the data analysis and modification is executed as close to the data as possible. Also it requires one network hop less as the Foxx has direct access to the data and does not have to query a database located on a different server. Second your application is completely free of any database related information like queries, it just requests an HTTP-endpoint that gives the data in the expected format. This also allows to reuse this endpoint in different applications without copying the queries. Third Foxx adds another level of security to your application, you can manage the access rights on any level you like: application, collection, document or even attribute. Finally Foxx is automatically scaled alongside your database: if the number of ArangoDB servers grows so does your Foxx servers, both have their bottleneck at the same point. In the recent movements of software development many companies of all sizes talk about moving away from large monolithic applications and switch over to a microservice based software architecture. Because microservices yield many benefits in terms of scaling and zero-downtime. During the design of Foxx we followed the concepts and ideas of microservices. Our baseline is the definition by Martin Fowler and James Lewis given in their [microservice article](http://martinfowler.com/articles/microservices.html). The following table lists a mapping of microservice concepts and how they can be realized within Foxx:
microservice | Foxx | description |
---|---|---|
Few lines of Code | Little Boilerplate | Most of the boilerplate is already handled by the Foxx environment. You can focus on your business logic. |
HTTP API | Controller | The Foxx controller allows to easily define HTTP API routes. |
Independently Deployable | Foxx Manager | Foxxes run in ArangoDB Coordinators. These are independent from one another. Foxxes can be installed on an arbitrary number of these Coordinators. |
Access other Microservices | Requests | The Foxx request module offers a simple functionality to contact any other API via HTTP. |
Scalability | Sharding | The dataset managed by a Foxx micro-service might be too large for a single server. The underlying ArangoDB infrastructure can handle this for you. |
Persistence | Repositories | Foxx is part of a multi-model database. It has all features to persist data of diverse formats (Graphs, Documents) built-in. |
Reuse Services | Arango Store | The Arango Store contains several Foxxes. Many of them are general-use services that are required in many applications. You can just reuse the reviewed and tested code of other Foxx users. |
Automated Deployment | Foxx Manager | The Foxx manager tool allows to trigger installation of new applications. Also there is a native system HTTP API offering this feature. You can use either one as a step in your build automation tool. |
Design for failure | Coordinators | ArangoDBs cluster setup is designed for failure. You can make use of this feature in your Foxxes. |
Different Languages | Connect to other APIs | Foxxes are only implemented in JavaScript. However not your entire application has to be written in Foxx. You can connect via HTTP to services in other languages. |
Different Databases | Multi-Model | In most setups you need different database technologies because you have several data formats. ArangoDB is a multi-model database that serves many formats. However if you still need another database you can connect to it via HTTP. |
Asynchronous Calls | Synchronous with multiple contexts | Foxx only allows synchronous execution. However it is executed in a multi-threaded fashion, hence blocking one thread is not a problem. Also background tasks are available for long-running tasks that should be executed outside of the request-response cycle. |
Security | Authentication and Session | Foxx offers internal APIs to handle authentication and manage session data. It is just a handful lines of code and your service is secured. |
Protected API | Libraries | Sometimes you have sensitive data that is not allowed to ever leave your database. Using libraries in Foxx you can write internal APIs that can only be accessed from the same server and are not exposed to the outside world. Perfect to keep your data inside but still using the paradigm of a microservice for it. |
How To | Recipes | In ArangoDBs cookbook there are several recipes on how to design a microservice based application with the help of Foxx. |
Maintenance UI | Built-in Web server | ArangoDB has a built-in Web server, allowing Foxxes to ship a Webpage as their UI. So you can attach a maintenance UI directly to your microservice and have it deployed with it in the same step. |
Easy Setup | ArangoDB on Mesos | ArangoDB perfectly integrates with the [Mesos project](http://mesos.apache.org/), a distributed kernel written for data centers. You can set up and deploy a Mesos instance running ArangoDB and having your microservice on top of it with just a single command. |
Maintenance | Marathon | If you are running ArangoDB on top of Mesos you can use [Marathon](https://mesosphere.github.io/marathon/) to keep all your instances alive and scale up or down with just a few clicks. Do not bother with long configuration, that is all handled by the underlying systems. |