Report for Elara v0.2
5 weeks ago, Patract Hub applied a treasury proposal for Elara v0.2. Now, we have finished all the development work on time. Please review our design, work, and enjory the seperated free services (1M requests per day) online at https://elara.patract.io. We have also privided a shared limited bandwidth node RPC service for Polkadot (wss://polkadot.elara.patract.io and https://polkadot.elara.patract.io), you can add it directly into your project and https://polkadot.js.org/apps.
Recap of the detailed design of Elara v0.2#
- Implement the account space features, supporting developers to use Github as a third-party login system to create an account space.
- Support the creating and management of multiple projects under the developer’s account space
- Provide developers with detailed access statistics features on the single project dimension, showing statistical indicators such as daily and weekly requests, calling methods, and source of user groups.
- Officially launch https://elara.patract.io, providing the community with public access services to the Polkadot mainnet
Now, let's show you the design and implementation of v0.2, and how to run and verify the work. With this micro-service architecture described blow, we can provide 5K requests per second and 500M requests per day for now. In the future, we will upgrade this architecture for 10 times improvements.
Architecture of Elara v0.2#
We had learned from Infura's work model, so that each development account can apply for multiple Projects to divide different Workspace, and then assign different Provider to access chain nodes. Therefore, the user's smallest resource unit is a Project. We have assigned an independent PID for each project. In the index of all resources, the developer can use this PID to find the information corresponding to this Project, such as detailed information, daily or weekly access statistics, etc.
Therefore, the architecture of Elara v0.2 is roughly as follows:

As can be seen from the above, in the backend management platform of Elara v0.2, the entire system is divided into 3 main modules:
Developer-Account: The module to manage the user's account login status.Stat: The module for management and data statistics ofProject.API: TheRoutemodule to manage user'sRequests.
In the overall design, the three modules are designed into a microservice architecture system, which can be independently extended. Because these three modules all run in independent processes after they are started, in the future, individual modules can be upgraded in parallel, such as expansion, reconstruction, and replacement. Among them, the Developer-Account module and the Stat module share data through a shared database, and the Stat and API are decoupled through the message queue kafka. In the future, it will be easy to add more complex functional modules based on this design to make Elara play a more powerful effect.
These three modules are responsible for different functions:
1. Developer-Account Module#
This module manages user account information and maintains login status. This module currently uses Redis to cache user information and maintain the user's login status. This login status is shared with the Stat module. Currently, this module uses Github's AccountID information to request authorization to access Github to create users.
Therefore, the external access interfaces provided by the module after running are:
- GET
/auth/login: Get login status information - GET
/auth/logout: logout, remove the user's login information. - GET
/auth/github: request authorization information from github - GET
/auth/github/callback: processing of callbacks authorized to github
2. Stat Module#
This module is mainly responsible for the management of Project, and counts the request information initiated by users from the API module in the dimensions of Project and users. This module is Consumer of kafka Message Middleware, which accepts request information sent from the API module and performs processing statistics. At the same time, the module shares the user's login status information with Developer-Account to check whether the user is still connected to Elara's webpage. In this module, each user can apply for the allocation of multiple Projects, representing a restricted resource unit in Elara, such as limiting the amount of requests and total bandwidth that a Project can accept per day.
The access interface of the Stat module uses PID as the basic element, and the PID of a project will be used as the specific node Provider of this project in the API module. In the process of using this PID to raise a node access request to the API, the developer will consume the resources managed under the project corresponding to this PID and accumulate the statistical information of this project.
Based on the above discussion, the Stat module is designed as follows:
- GET
/project/list: List all project information under the currently logged-in user, and return:
{ "code": 0, "message": "", "data": [ { "id": "b78a79f98a2bb1a991a357504a5b04c1", "status": "Active", "chain": "substrate", "name": "thedao", "uid": "...", "secret": "...", "createtime": "1600398327", "lasttime": "1600398327", "allowlist": "false" }, ... ]}The id in the returned information is the PID of a Project.
- GET
/project/<PID>: Returns the detailed information associated with thisProject. - POST
/project/create: Create a newProjectbased on the information of the currently logged in user
Parameters:
chain:<Polkdaot|Kusama>name:<Validation rules /[a-zA-Z]{4,32}/>- GET
/stat/day/<PID>: Get the statistics of aProjectin one day - GET
/stat/day/<PID>: Get the statistical information of aProjectwithin one week - See the document for other interface definitions: Stat README
3. API Module#
After receiving requests from different users, the API module distinguishes which request to a Project according to the PID carried in the routing information, sends the corresponding information to the kafka queue, and forwards the user request to the corresponding node. Therefore, for the API module, Elara designed the following two access interfaces, among which the parameters of <chain> can currently be filled in Polkadot and Kusama.
- HTTPS, POST
/<chain>/<PID>: Accept the RPC request initiated by the user. The parameters of the request are all RPC interfaces that the node provides external services - Websocket
/<chain>/<PID>: Accept the Websocket request initiated by the user. The parameters of the request are all RPC interfaces that the node provides external services
The above three modules work together to provide Elara's back-end components. Adding a front-end kit on top of it can become a complete Elara product to provide external services: https://elara.patract.io/ The sample screenshot is as follows:
This module is used to provide node services. It is mainly responsible to proxy user's node access request (RPC & websocket) to the node, and as the Producer of the kafka message queue, it sends the relevant information of the user request to the Stat module. In the API module, the user composes the PID created in the Stat module into the URL of the access node Provider, and then initiates a node access request to the API module.
4. Summary#
The above three modules work together to provide Elara's back-end components. Adding a front-end kit on top of it can become a complete Elara product to provide external services: https://elara.patract.io/ The sample screenshot is as follows:

Run Elara#
The processes corresponding to the above 3 modules need to be started in sequence in the following order to make Elara work properly: 1, Developer-Account, 2, Stat, 3.API
Environment preparation#
Elara's operating environment requires redis and kafka support. Therefore, before running the following commands, first ensure that there is a running redis instance in the running environment and the executable file of kafka has been installed. The 3 processes of Elara are run by node, so you need to install the corresponding dependencies with the yarn command before running.
Start Services#
Start
Developer-AccountService- Enter
elara/packages/accountdirectory$ cd package/account - Install dependence
$ yarn install - Modify the configuration file of the
Developer-Accountservice, including theredisfield and thegithubfield. The default port is set to7001, so if theportdomain is not modified, the service will occupy the7001port after startup.$ vim ./config/env/dev.env.js - Start the service, and the log output by the process is located in the
./logsdirectory.$ node app.js# or use pm2 to manage process$ pm2 start pm2.json --env dev
- Enter
Start
StatService- Enter
elara/packages/statdirectory(If you are inaccountdirectory)$ cd ../stat - Install dependence
$ yarn install - Switch to the
kafkadirectory, start thekafkadirectory and set thetopic- Start
kafkaand related processes. If the configuration file ofkafkais not modified, port9092will be occupied by default.$ cd <the root directory of kafka>$ bin/zookeeper-server-start.sh config/zookeeper.properties$ bin/kafka-server-start.sh config/server.properties - Add
elara-devtopic tokafka# add `elara-dev` topic to kafka$ bin/kafka-topics.sh --create --topic elara-dev --bootstrap-server localhost:9092# check whethere this topic is inittedbin/kafka-topics.sh --describe --topic elara-dev --bootstrap-server localhost:9092
- Start
- Switch to
elara/packages/statdirectory,modify the configration file ofStatmodule.$ vim ./config/env/dev.env.js- Since
StatandDeveloper-Accountshare the sameredisinstance, the configuration of theredisfield in this configuration file should be consistent with the configuration ofredisin theDeveloper-Accountconfiguration file . - The
kafkadomain here needs to be consistent with the configuration of startingkafkain the previous step. - If it is only used for local testing, please modify the
test:falsein the default configuration totest:true. After enabling this flag, when accessing the interface provided bystat, the login status of the login account will not be verified, and all interfaces can be directly accessed. In a production environment, please ensure that the value of thetestfield isfalse. - The default
portdomain in the configuration file is7002, so if you do not modify this value, it will occupy the7002port to provide services after startup.
- Since
- Start Services
- Start the
statservice. If you do not modify the port after startup, the7002port will be occupied. The following text uses127.0.0.1:7002as the service address performed bystat. The log output by the process is located in the./logsdirectory.$ node app.js# or use pm2 to manage process$ pm2 start pm2.json --env dev - Start
kafkaconsumer service$ node ./kafka/consumer.js - If you need to see the console information, you need to start the
dashboardserviceAt this point, you can open$ node ./timer/dashboard.jshttp://127.0.0.1:7002/dashboardin the browser to see the statistics information of the monitoring station.
- Start the
- Enter
Start
APIServiceEnter
elara/packages/apidirectory(if you are instat)$ cd ../apiInstall dependence
$ yarn installModify the configuration file of the
APImodule$ vim ./config/env/dev.env.js- The
chainfield is used to configure the real chain node, where the name of the chain is part of the route provided by theapito the developer. For example, if there are the following configurations in the default, the access method of/Polkadot/<PID>is supported in the routing supported by the API.'Polkadot': { 'rpc': ['****:**'], //configure as node http://IP: RPC port in step 2 'ws': ['****:**'] //configure as node ws://IP: WS port in step 2} - The
kafkafield is used to configure the information of thekafkaprocess started in thestatsection. Note that the configured topic is the topicelara-devregistered tokafkawhen thestatpart is configured. , startServerfiled is used to configure the ip and port of thestatprocess. For example, ifapiandstatare on the same host and the default configuration is used (that is,statoccupies port 7002 by default), then The value here is127.0.0.1:7002portfield is used to configure the port occupied by theapiservice process, the default configuration is 7003
- The
Start Services
$ node app.js# or use pm2 to manage process$ pm2 start pm2.json --env devAt this time the service has been started, if the port is not modified, the port
7003will be occupied. The following text uses the port127.0.0.1:7003as the host for user access. The log output by the process is located in the./logsdirectory.
Call Elara#
Since the configuration of test:true is used when starting stat in the above case, the process of user login is skipped in the following process, and the process of creating Project is directly started.
Create Project:
Send a request to create a project to the service address
127.0.0.1:7002ofstat: This project is a request for access to thePolkadotchain, so the value of the parameterchainis specified asPolkadot.POST http://127.0.0.1:7002/project/create chain:Polkadotname:helloReturn:
{ "code": 0, "mssage": "", "data": { "id": "5d4ebb40b08f127652ad022f5936b9da", "status": "Active", "chain": "Polkadot", "name": "hello", "uid": "Only For Test", "secret": "0b89a386965bfe4dcb19f724ecb41890", "createtime": "1606581366", "lasttime": "1606581366", "allowlist": "false" }}You can get the detailed information of creating
ProjectandPID, here is5d4ebb40b08f127652ad022f5936b9daList all the
Projectsfor this userGET http://127.0.0.1:7002/project/listReturn:
{ "code": 0, "message": "", "data": [ { "id": "5d4ebb40b08f127652ad022f5936b9da", "status": "Active", "chain": "Polkadot", "name": "hello", "uid": "Only For Test", "secret": "0b89a386965bfe4dcb19f724ecb41890", "createtime": "1606581366", "lasttime": "1606581366", "allowlist": "false" } ]}Since testing is currently enabled, all
Projectinformation will be listed. If the test is not turned on, only the information list ofProjectfor the current login will be listed.Use this PID as part of the route to initiate an access request to the node.
The access request to the node needs to be served through
API, the currentAPIservice address is127.0.0.1:7003, so we can initiate the following request: The access route is<api server host>/<project chain>/< PID>composition, so in this case- The access address for rpc is
http://127.0.0.1:7003/Polkadot/5d4ebb40b08f127652ad022f5936b9da - The access address for websocket is
ws://127.0.0.1:7003/Polkadot/5d4ebb40b08f127652ad022f5936b9da
POST http://127.0.0.1:7003/Polkadot/5d4ebb40b08f127652ad022f5936b9da { "id":1, "jsonrpc":"2.0", "method":"system_chain", "params":[ ]}APIService is normal and return:{ "jsonrpc": "2.0", "result": "Polkadot", "id": 1}This request will be counted by Elara normally and recorded that project
5d4ebb40b08f127652ad022f5936b9dahas one request.- The access address for rpc is
If you want to test whether the api service can satisfy normal node requests, you can add the websocket access link to
Polkadot/Substrate Portal。Log in to the Portal web page in the browser
Click on the upper left corner
Click on the
DEVELOPMENTcolumn and click on theCustomcolumn to fill inws://127.0.0.1:7003/Polkadot/5d4ebb40b08f127652ad022f5936b9daClick "Switch"

At this point the Portal should be able to work normally, and all access requests are recorded by Elara.
Access the
Statservice to get statisticsSuch as listing all the visit statistics of the current project in the day
GET http://127.0.0.1:7002/stat/day/5d4ebb40b08f127652ad022f5936b9daOr list the statistics of this project this week
GET http://127.0.0.1:7002/stat/week/5d4ebb40b08f127652ad022f5936b9daVisit
http://127.0.0.1:7002/dashboardand you can see the total statistics from the console.
At this point, the entire system can operate normally.
验证#
Developers can use Github account to log in to the developer account space from https://elara.patract.ioAnyone can currently get access to the Polkadot chain through this link.
Developers can create new projects and access related API keys under the accountThe above process has introduced the concept of project, and you can log in to github with authorization and create a project at https://elara.patract.io.
Developers can access the Polkadot node in Elara through Http and web-socket protocols
The
APIservice is used to support this function, and the corresponding operations have been shown aboveDevelopers can view the monitoring statistics of the projects on the day and the recent weeks
The
/stat/day/<PID>and/stat/week/<PID>interfaces ofStatservice are used to support this function.You can view the relevant monitoring statistics from the Elara dashboard
You can see the corresponding information from the
http://127.0.0.1:7002/dashboardconsole.