Skip to content

Production-ready C++ Asynchronous Framework with rich functionality

License

Notifications You must be signed in to change notification settings

userver-framework/userver

This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

99f96fb · Jan 8, 2025
Dec 28, 2024
Dec 20, 2024
Dec 19, 2024
Dec 27, 2024
Dec 28, 2024
Jan 8, 2025
Dec 26, 2024
Dec 27, 2024
Dec 25, 2024
Dec 27, 2024
Dec 25, 2024
Dec 26, 2024
Dec 20, 2024
Nov 18, 2024
Dec 27, 2024
Dec 25, 2024
Dec 26, 2024
Dec 28, 2024
Dec 17, 2024
Dec 12, 2024
Nov 29, 2024
Jan 8, 2025
Dec 18, 2024
Oct 20, 2024
Jul 1, 2024
Sep 7, 2023
Oct 25, 2023
Oct 16, 2024
Dec 28, 2024
Oct 21, 2024
Mar 31, 2024
Dec 27, 2024
Feb 8, 2024
Oct 4, 2023
Oct 31, 2024
Nov 8, 2021
Oct 15, 2024
Dec 17, 2024
Feb 21, 2023
Mar 20, 2024
Dec 27, 2024
May 23, 2024

Repository files navigation

userver

Service Templates Develop / Green Trunk v2.0 v1.0
Core: CI Docker build [➚] [➚]
PostgreSQL: CI Docker build [➚] [➚]
gRPC+PostgreSQL: CI Docker build [➚] [➚]

userver is an open source asynchronous framework with a rich set of abstractions for fast and comfortable creation of C++ microservices, services and utilities.

The framework solves the problem of efficient I/O interactions transparently for the developers. Operations that would typically suspend the thread of execution do not suspend it. Instead of that, the thread processes other requests and tasks and returns to the handling of the operation only when it is guaranteed to execute immediately:

#include <userver/easy.hpp>
#include "schemas/key_value.hpp"

int main(int argc, char* argv[]) {
    using namespace userver;

    easy::HttpWith<easy::PgDep>(argc, argv)
        // Handles multiple HTTP requests to `/kv` URL concurrently
        .Get("/kv", [](formats::json::Value request_json, const easy::PgDep& dep) {
            // JSON parser and serializer are generated from JSON schema by userver
            auto key = request_json.As<schemas::KeyRequest>().key;

            // Asynchronous execution of the SQL query in transaction. Current thread
            // handles other requests while the response from the DB is being received:
            auto res = dep.pg().Execute(
                storages::postgres::ClusterHostType::kSlave,
                // Query is converted into a prepared statement. Subsequent requests
                // send only parameters in a binary form and meta information is
                // discarded on the DB side, significantly saving network bandwidth.
                "SELECT value FROM key_value_table WHERE key=$1", key
            );

            schemas::KeyValue response{key, res[0][0].As<std::string>()};
            return formats::json::ValueBuilder{response}.ExtractValue();
        });
}

As a result, with the framework you get straightforward source code, avoid CPU-consuming context switches from OS, efficiently utilize the CPU with a small amount of execution threads.

You can learn more about history and key features of userver from our publications and videos.

Other Features

  • Efficient asynchronous drivers for databases (MongoDB, PostgreSQL, Redis, ClickHouse, MySQL/MariaDB, YDB ...) and data transfer protocols (HTTP/{1.1, 2.0}, gRPC, AMQP 0-9-1, Kafka, TCP, TLS, WebSocket ...), tasks construction and cancellation.
  • Rich set of high-level components for caches, tasks, distributed locking, logging, tracing, statistics, metrics, JSON/YAML/BSON.
  • Functionality to change the service configuration on-the-fly.
  • On-the-fly configurable drivers, options of the deadline propagation, timeouts, congestion-control.
  • Comprehensive set of asynchronous low-level synchronization primitives and OS abstractions.

See the docs for more info.