Introducing Horizon: build realtime apps without writing backend code-Alibaba Cloud Developer Community

Original: Introducing Horizon: build realtime apps without writing backend code

today, we are very honored to announce the first official release of Horizon, an open-source backend service that can help developers build and expand real-time web applications. The Horizon include:

Horizon server is a complete backend service that developers can use to drive their applications. It is ideal for implementing rapid prototypes: simply run Horizon server through the command line, and use Horizon client library to improve the user experience of your front-end. With Horizon, frontend developers can develop a complete application without writing a line of backend code.

Horizon is an open-source software, that is, you can use and modify it according to your preferences. Run a local instance on your notebook during development, and then deploy it to any place you want to deploy: low-cost VPS hosts, public clouds, or bare metal. Horizon rely on RethinkDB and reliable clusters, which can be easily expanded after your users grow.

In addition to the open-source Horizon backend, we have built a Cloud service that can be used to deploy, manage, and expand Horizon applications. Horizon Cloud, we manage Horizon backend services and underlying RethinkDB databases, it can also be automatically expanded as needed. Horizon Cloud also provides built-in support for backup and recovery, no downtime version update, monitoring, and other practical functions. Developers can use Horizon command line tools to deploy their applications to Horizon Cloud. Horizon Cloud is still in the internal testing stage, but it won't be long before we meet with you.

Why is it Horizon

last year, when introducing changefeeds brought by RethinkDB 1.16, we shared a plan to promote real-time web. You no longer need to obtain data updates through polling. Developers can tell the database to push the real-time application results as continuous streams. When we share this function with users, a question is asked over and over: Can I directly access RethinkDB real-time updates from the web application of the browser?

changefeeds was initially designed for backend developers to decide how to transmit real-time updates to the front end. Shortly after we launched this feature, we began to consider whether it would be awesome to expose real-time data streams directly to browsers. WebSocket abstract Library, GraphQL new data retrieval technology, and RxJS Observables powerful asynchronous stream source, provides the front-end with new si to retrieve and process data. Web applications are evolving and beyond the capabilities of REST and XMLHttpRequest. Horizon is created for the future. It uses real-time data streams to connect the database and the front end.

Horizon reduces the trouble faced by developers when building and expanding web applications. It eliminates repeated templates and tedious steps, such as handwritten CRUD endpoints, user authentication, and session management. We are committed to filling the gap between the data persistence layer and the front end, freeing developers from the cycle of continuous invention, allowing them to focus more time on implementing business logic.

Get started Horizon

before using Horizon, install Horizon library package from NPM, which contains a command line tool named hz that you can use to generate and run your first project. You can find detailed installation instructions and concise tutorials on the Horizon official website.

Horizon client library provides a concise API. You can use a chain method to express database queries. The returned query RxJS Observables allows you to merge and process the query results. Behind this, Horizon data set is based on RethinkDB tables. When Horizon is run in development mode, the server automatically creates the required tables and indexes.

The following example shows how to use the Horizon client library in a browser or other front-end environment. This code shows how to store JSON documents in a Horizon collection and obtain a filtered subset from the collection records:

var horizon = Horizon();
var messages = horizon("messages");
messages.store({
  sender: "Bob",
  time: new Date(),
  text: "Hello, World!"
});
messages.findAll({sender: "Bob"}).fetch()
        .subscribe(m => console.log(m));

if you want to continuously execute queries and obtain real-time updated stream data, you only need to use the 'watch' method. The following example shows how to implement real-time ranking in online games through Horizon queries:

var users = horizon("users");
users.order("score", "descending").limit(5).watch()
     .subscribe(items => console.log(items))

the top five queries are sorted in descending order according to the user's score. Whenever the value changes, the 'subscribe' callback obtains a complete array containing the updated content, which automatically maintains the sorting order and adds and deletes users as needed.

Horizon server translates the client query into ReQL, that is, the query language of the RethinkDB. Automatically generated indexes are used in the query translation process to maximize efficiency and performance. The query language of Horizon is simpler and easier to use than that of ReQL, making it easy for developers to learn and optimize their servers. The following is a list of supported commands:

  • find, findAll
  • above, below, limit, order
  • remove, removeAll
  • store, upsert, replace
  • watch, fetch

you can refer to Horizon documentation to learn more about how to use the client library API. We are working on a series of improvements to improve the ability and expressiveness of query languages. For example, one feature allows you to combine multiple queries into model relationships.

Integrate Horizon and Javascript ecosystem

Horizon is neither mandatory nor self-righteous-it itself is designed to be used in conjunction with your favorite JavaScript framework. Horizon server has strong scalability, that is, developers who want to customize backend services can embed Horizon into Node.js applications as needed, and add new features as needed. You can even integrate Horizon into existing Node.js backend applications and have fun with conventional frameworks such as Express,Koa, and Hapi.

Horizon the client library uses a simple WebSocket-based protocol to communicate with the server, we provide a pure abstraction layer. You do not need to manage persistent connections or care about how the WebSockets works. Horizon client library can be used with any front-end framework, such as React,Angular,Ember, and vanilla JavaScript (the most popular JavaScript framework in the world :). You can also use it with front-end status managers like redux.

You can find an example in Horizon official Github repository to show how to integrate Horizon with various front-end and back-end frameworks. React developers can also take a look at lovli.js, a practical template written by Patrick Neschkudla, which uses Horizon,React, and Redux.

We look forward to moving Horizon client library to the mobile platform one day. We are also actively working with the community to ensure that Horizon JavaScript clients can work normally on Electron and React Native. JavaScript is penetrating into various places, from embedded Internet of Things systems to desktop and mobile applications. We believe that Horizon can provide some reasons for developers to choose JavaScript.

In addition, we have compiled a document for the underlying protocol for communication between the client library and the Horizon backend. Developers can use this protocol to build client libraries in other languages. This protocol includes simple JSON files. Based on engine.io, it is a real-time framework that supports multiple network transmission.

Planning

the Horizon released today is only a starting point, far from the final goal. You will see new features and improvements in the project progress. Existing features include query, real-time update, authentication, permission system, and support for static resources.

Some of the main features are not mature enough. The permission system and verification support were recently added and were included in the development cycle very late. When we begin to improve these functions, you may encounter some imperfections.

Long-term planning is still growing, but the following list is what we want to include in future versions:

You can pay attention to the daily updates on the Horizon forum, and we will try our best to improve these functions and stabilize Horizon code.

Community participation

  • Horizon: the realtime, open-source JavaScript backend
  • Horizon forum
  • GitHub - rethinkdb/horizon: Horizon is a realtime, open-source backend for JavaScript apps
  • Join RethinkDB on Slack
  • https://twitter.com/horizonjs

we look forward to cooperating with you. We take promoting the development of real-time web as our mission.

Selected, One-Stop Store for Enterprise Applications
Support various scenarios to meet companies' needs at different stages of development

Start Building Today with a Free Trial to 50+ Products

Learn and experience the power of Alibaba Cloud.

Sign Up Now