Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up

Microservices framework

License

NotificationsYou must be signed in to change notification settings

deriv-com/perl-Myriad

Repository files navigation

Myriad - microservice coördination

Coverage statusDocker

SYNOPSIS

use Myriad;Myriad->new->run;

DESCRIPTION

Myriad provides a framework for dealing with asynchronous, microservice-based code.It is intended for use in an environment such as Kubernetes to support horizontalscaling for larger systems.

Overall this framework encourages - but does not enforce - single-responsibilityin each microservice: each service should integrate with at most one external system,and integration should be kept in separate services from business logic or aggregation.This is at odds with common microservice frameworks, so perhaps it would be more accurateto say that this framework is aimed at developing "nanoservices" instead.

Do you need this?

If you expect to be dealing with more traffic than a single server can handle,or you have a development team larger than 30-50 or so, this might be of interest.

For a smaller system with a handful of users, it'sprobably overkill!

Modules and code layout

Each of the three abstractions has various implementations. You'd set one on startupand that would provide functionality through the top-level abstraction layer. Service codegenerally shouldn't need to care which implementation is applied. There may however be caseswhere transactional behaviour differs between implementations, so there is some basicfunctionality planned for checking whether RPC/storage/subscription use the same underlyingmechanism for transactional safety.

Storage

TheMyriad::Storage abstract API is a good starting point here.

For storage implementations, we have:

Additional transport mechanisms may be available, see CPAN for details.

RPC

Simple request/response patterns are handled with theMyriad::RPC layer ("remote procedure call").

Details on the request are inMyriad::RPC::Request and the response to be sent back is inMyriad::RPC::Response.

Additional transport mechanisms may be available, see CPAN for details.

Subscriptions

TheMyriad::Subscription abstraction layer defines the available API here.

Subscription implementations include:

Additional transport mechanisms may be available, see CPAN for details.

Transports

Note thatsome layers don't have implementations for all transports - MQ for example does not really provide a concept of "storage".

Each of these implementations is supposed to separate out the logic from the actual transport calls, so there's a separate ::Transport set of classes here:

which deal with the lower-level interaction with the protocol, connection management and so on. More details on thatcan be found inMyriad::Transport - but it's typically only useful for people working on theMyriad implementation itself.

Other classes

Documentation for these classes may also be of use:

METHODS

loop

Returns the mainIO::Async::Loop instance for this process.

services

Hashref of services that have been added to this instance,asname =>Myriad::Service pairs.

configure_from_argv

Applies configuration from commandline parameters.

Expects a list of parameters and applies the following logic for each one:

  • if it contains:: and a wildcard*, it's treated as a service module base name, and allmodules under that immediate namespace will be loaded
  • if it contains::, it's treated as a comma-separated list of service module names to load
  • a- prefix is a standard getopt parameter

transport

Returns theMyriad::Transport instance according to the config value.

it's designed to be used by tests, so be careful before using it in the framework code.

it takes a single param

  • component - the RPC, Subscription or storage in lower case

redis

TheNet::Async::Redis (or compatible) instance used for service coördination.

memory_transport

TheMyriad::Transport::Memory instance.

rpc

TheMyriad::RPC instance to serve RPC requests.

rpc_client

TheMyriad::RPC::Client instance to request other services RPC.

http

TheNet::Async::HTTP::Server (or compatible) instance used for health checksand metrics.

subscription

TheMyriad::Subscription instance to manage events.

storage

TheMyriad::Storage instance to manage data.

registry

Returns the commonMyriad::Registry representing the current service state.

add_service

Instantiates and adds a new service to the"loop".

Returns the service instance.

service_by_name

Looks up the given service, returning the instance if it exists.

Will throw an exception if the service cannot be found.

ryu

a source to corresponde to any high level events.

shutdown

Requests shutdown.

on_start

Registers a coderef to be called during startup.The coderef is expected to return aFuture.

on_shutdown

Registers a coderef to be called during shutdown.

The coderef is expected to return aFuture indicating completion.

run_future

Returns a copy of the runFuture.

This would resolve once the process is running and it'sready to accept requests.

shutdown_future

Returns a copy of the shutdownFuture.

This would resolve once the process is about to shut down,triggered by a fault or a Unix signal.

setup_logging

Prepare for logging.

setup_tracing

PrepareOpenTracing collection.

setup_metrics

PrepareMetrics::Any::Adapter to collect metrics.

run

Starts the main loop.

Applies signal handlers for TERM and QUIT, then starts the loop.

SEE ALSO

Microservices are hardly a new concept, and there's a lot of prior art out there.

Key features that we attempt to provide:

  • reliable handling - requests and actions should be reliable by default
  • atomic storage - being able to record something in storage as part of the same transaction as acknowledging a message
  • flexible backends - support for various storage, RPC and subscription implementations, allowing for mix+match
  • zero transport option - for testing and smaller deployments, you might want to run everything in a single process
  • language-agnostic - implementations should be possible in languages other than Perl
  • first-class Kubernetes support - k8s is not required, but when available we should play to its strengths
  • minimal boilerplate - with an emphasis on rapid prototyping

These points tend to be incompatible with typical HTTP-based microservices frameworks, although this isoffered as one of the transport mechanisms (with some limitations).

Perl

Here are a list of the Perl microservice implementations that we're aware of:

Java

Although this is the textbook "enterprise-scale platform", Java naturally fits a microservice theme.

  • Spring Boot - One of the frameworks that integrates wellwith the traditional Java ecosystem, depends on HTTP as a transport. Although there is no unified storage layer,database access is available through connectors.
  • Micronaut - This framework has many integrations with industry-standardsolutions - SQL, MongoDB, Kafka, Redis, gRPC - and they have integration guides for cloud-native solutionssuch as AWS or GCP.
  • DropWizard - A minimal framework that provides a RESTfulinterface and storage layer using Hibernate.
  • Helidon - Oracle's open source attempt, provides support for two types oftransport and SQL access layer using standard Java's packages, built with cloud-native deployment in mind.

Python

Most of Python's frameworks provide tools to facilitate building logic blocks behind APIs (Flask, Django ..etc).

For work distribution,Celery is commonly used as a task queue abstraction.

Rust

  • https://rocket.rs/ - although this is a web framework, rather than a complete microservice system,it's reasonably popular for the request/response part of the equation
  • https://actix.rs/ - another web framework, this time with a focus on the actor pattern

JS

JS has many frameworks that help to implement the microservice architecture, some are:

  • Moleculer - generally a full-featured, well-designed microservices framework, highly recommended
  • Seneca

PHP

  • Swoft - async support via Swoole's coroutines, HTTP/websockets based with additional support for Redis/database connection pooling and ORM

Cloud providers

Microservice support at the provider level:

  • AWS Lambda - trigger small containers based on logic, typically combinedwith other AWS services for data storage, message sending and other actions
  • "Google App Engine" - Google's own attempt
  • Heroku - Allow developers to build a microservices architecture based on the services they providelike the example they mentioned in thisblog

AUTHOR

Deriv Group Services Ltd.DERIV@cpan.org

CONTRIBUTORS

  • Tom MolesworthTEAM@cpan.org
  • Paul EvansPEVANS@cpan.org
  • Eyad Arnabeh
  • Nael Alolwani

LICENSE

Copyright Deriv Group Services Ltd 2020-2022. Licensed under the same terms as Perl itself.

About

Microservices framework

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp