Giter Club home page Giter Club logo

event-gateway's Introduction

Event Gateway - React to any event with FaaS function across clouds

We're Hiring!WebsiteSlackNewsletterForumMeetupsTwitter

The Event Gateway combines both API Gateway and Pub/Sub functionality into a single event-driven experience. It's dataflow for event-driven, serverless architectures. It routes Events (data) to Functions (serverless compute). Everything it cares about is an event! Even calling a function. It makes it easy to share events across different systems, teams and organizations!

Use the Event Gateway right now, by running the Event Gateway Getting Started Application with the Serverless Framework.

Features:

  • Platform agnostic - All your cloud services are now compatible with one another: share cross-cloud functions and events with AWS Lambda, Microsoft Azure, IBM Cloud and Google Cloud Platform.
  • Send events from any cloud - Data streams in your application become events. Centralize events from any cloud provider to get a bird’s eye view of all the data flowing through your cloud.
  • React to cross-cloud events - You aren’t locked in to events and functions being on the same provider: Any event, on any cloud, can trigger any function. Set events and functions up like dominoes and watch them fall.
  • First-class support for CloudEvents - Emit and react to events in CloudEvents standard.
  • Expose events to your team - Share events and functions to other parts of the application. Your teammates can find them and utilize them in their own services.
  • Extendable through middleware - Perform data transforms, authorizations, serializations, and other custom computes straight from the Event Gateway.

The Event Gateway is a L7 proxy and realtime dataflow engine, intended for use with Functions-as-a-Service on AWS, Azure, Google & IBM.

The project is under heavy development. The APIs will continue to change until we release a 1.0.0 version. It's not yet ready for production applications.

Build Status

Event Gateway - Build event-driven integrations with lambda, cloud functions, kubernetes

Contents

  1. Quick Start
  2. Running the Event Gateway
  3. Motivation
  4. Components
    1. Event Registry
    2. Function Discovery
    3. Subscriptions
    4. Spaces
  5. CloudEvents Support
  6. SDKs
  7. Versioning
  8. FAQ
  9. Background
  10. Community

Reference

  1. API
  2. Event Types
  3. Subscription Types
  4. Architecture
  5. Clustering
  6. System Events and Plugin System
  7. System Metrics
  8. Reliability Guarantees

Quick Start

Getting Started

Looking for an example to get started? The easiest way to use the Event Gateway is with the serverless-event-gateway-plugin with the Serverless Framework. Check out the Getting Started Example to deploy your first service to the Event Gateway.

Running the Event Gateway

Hosted version

If you don't want to run the Event Gateway yourself, you can use the hosted version provided by the Serverless team. Sign up here!

via Docker

There is an official Docker image.

docker run -p 4000:4000 -p 4001:4001 serverless/event-gateway --dev

Binary

On macOS or Linux run the following to download the binary:

curl -sfL https://raw.githubusercontent.com/serverless/event-gateway/master/install.sh | sh

On Windows download binary.

Then run the binary in development mode with:

$ event-gateway --dev

Kubernetes

The repo contains helm charts for a quick deploy to an existing cluster using native nginx Ingress. To deploy a development cluster you can follow the minikube instructions.


If you want more detailed information on running and developing with the Event Gateway, please check Running Locally and Developing guides.

Motivation

  • It is cumbersome to plug things into each other. This should be easy! Why do I need to set up a queue system to keep track of new user registrations or failed logins?
  • Introspection is terrible. There is no performant way to emit logs and metrics from a function. How do I know a new piece of code is actually working? How do I feed metrics to my existing monitoring system? How do I plug this function into to my existing analytics system?
  • Using new functions is risky without the ability to incrementally deploy them.
  • The AWS API Gateway is frequently cited as a performance and cost-prohibitive factor for using AWS Lambda.

Components

Event Registry

Event Registry is a single source of truth about events occuring in the space. Every event emitted to a space has to have event type registered beforehand. Event Registry also provides a way to authorize incoming events. Please check Event Types reference for more information.

Function Discovery

Discover and call serverless functions from anything that can reach the Event Gateway. Function Discovery supports the following function types:

  • FaaS functions (AWS Lambda, Google Cloud Functions, Azure Functions, IBM Cloud Functions)
  • Connectors (AWS Kinesis, AWS Kinesis Firehose, AWS SQS)
  • HTTP endpoints/Webhook (e.g. POST http://example.com/function)

Function Discovery stores information about functions allowing the Event Gateway to call them as a reaction to received event.

Example: Register An AWS Lambda Function

curl example
curl --request POST \
  --url http://localhost:4001/v1/spaces/default/functions \
  --header 'content-type: application/json' \
  --data '{
    "functionId": "hello",
    "type": "awslambda",
    "provider":{
      "arn": "arn:aws:lambda:us-east-1:377024778620:function:bluegreen-dev-hello",
      "region": "us-east-1"
    }
}'
Node.js SDK example
const eventGateway = new EventGateway({ url: 'http://localhost' })
eventGateway.registerFunction({
  functionId: 'sendEmail',
  type: 'awslambda',
  provider: {
    arn: 'xxx',
    region: 'us-west-2'
  }
})

Subscriptions

Lightweight pub/sub system. Allows functions to asynchronously receive custom events. Instead of rewriting your functions every time you want to send data to another place, this can be handled entirely in configuration using the Event Gateway. This completely decouples functions from one another, reducing communication costs across teams, eliminates effort spent redeploying functions, and allows you to easily share events across functions, HTTP services, even different cloud providers. Functions may be registered as subscribers to a custom event. When an event occurs, all subscribers are called asynchronously with the event as its argument.

Creating a subscription requires providing ID of registered function, an event type, an HTTP method (POST by default), and a path (/ by default). The method and path properties defines HTTP endpoint which Events API will be listening on.

Event Gateway supports two subscription types: async and sync. Please check Subscription Types reference for more information.

Example: Subscribe to an Event

curl example
curl --request POST \
  --url http://localhost:4001/v1/spaces/default/subscriptions \
  --header 'content-type: application/json' \
  --data '{
    "type": "async",
    "eventType": "user.created",
    "functionId": "sendEmail",
    "path": "/myteam"
  }'
Node.js SDK example
const eventGateway = new EventGateway({ url: 'http://localhost' })
eventGateway.subscribe({
  type: 'async',
  eventType: 'user.created',
  functionId: 'sendEmail',
  path: '/myteam'
})

sendEmail function will be invoked for every user.created event to <Events API>/myteam endpoint.

Example: Emit an Event

curl example
curl --request POST \
  --url http://localhost:4000/ \
  --header 'content-type: application/json' \
  --data '{
    "eventType": "myapp.user.created",
    "eventID": "66dfc31d-6844-42fd-b1a7-a489a49f65f3",
    "cloudEventsVersion": "0.1",
    "source": "/myapp/services/users",
    "eventTime": "1990-12-31T23:59:60Z",
    "data": { "userID": "123" },
    "contentType": "application/json"
  }'
Node.js SDK example
const eventGateway = new EventGateway({ url: 'http://localhost' })
eventGateway.emit({
  "eventType": "myapp.user.created",
  "eventID": "66dfc31d-6844-42fd-b1a7-a489a49f65f3",
  "cloudEventsVersion": "0.1",
  "source": "/myapp/services/users",
  "eventTime": "1990-12-31T23:59:60Z",
  "data": { "userID": "123" },
  "contentType": "application/json"
})

Example: Subscribe to an http.request Event

Not all data are events that's why Event Gateway has a special, built-in http.request event type that enables subscribing to raw HTTP requests.

curl example
curl --request POST \
  --url http://localhost:4001/v1/spaces/default/subscriptions \
  --header 'content-type: application/json' \
  --data '{
    "type": "sync",
    "eventType": "http.request",
    "functionId": "listUsers",
    "method": "GET",
    "path": "/users"
  }'
Node.js SDK example
const eventGateway = new EventGateway({ url: 'http://localhost' })
eventGateway.subscribe({
  type: 'sync',
  eventType: 'http.request',
  functionId: 'listUsers',
  method: 'GET',
  path: '/users'
})

listUsers function will be invoked for every HTTP GET request to <Events API>/users endpoint.

Spaces

One additional concept in the Event Gateway are Spaces. Spaces provide isolation between resources. Space is a coarse-grained sandbox in which entities (Functions and Subscriptions) can interact freely. All actions are possible within a space: publishing, subscribing and invoking.

Space is not about access control/authentication/authorization. It's only about isolation. It doesn't enforce any specific subscription path.

This is how Spaces fit different needs depending on use-case:

  • single user - single user uses default space for registering function and creating subscriptions.
  • multiple teams/departments - different teams/departments use different spaces for isolation and for hiding internal implementation and architecture.

Technically speaking Space is a mandatory field ("default" by default) on Function or Subscription object that user has to provide during function registration or subscription creation. Space is a first class concept in Config API. Config API can register function in specific space or list all functions or subscriptions from a space.

CloudEvents Support

Event Gateway has the first-class support for CloudEvents. It means few things.

First of all, if the event emitted to the Event Gateway is in CloudEvents format, the Event Gateway is able to recognize it and trigger proper subscriptions based on event type specified in the event. Event Gateway supports both Structured Content and Binary Content modes described in HTTP Transport Binding spec.

Secondly, there is a special, built-in HTTP Request Event type allowing reacting to raw HTTP requests that are not formatted according to CloudEvents spec. This event type can be especially helpful for building REST APIs.

Currently, Event Gateway supports CloudEvents v0.1 schema specification.

SDKs

Versioning

This project uses Semantic Versioning 2.0.0. We are in initial development phase right now (v0.X.Y). The public APIs should not be considered stable. Every breaking change will be listed in the release changelog.

FAQ

What The Event Gateway is NOT

  • it's not a replacement for message queues (no message ordering, currently weak durability guarantees only)
  • it's not a replacement for streaming platforms (no processing capability and consumers group)
  • it's not a replacement for existing service discovery solutions from the microservices world

Event Gateway vs FaaS Providers

The Event Gateway is NOT a FaaS platform. It integrates with existing FaaS providers (AWS Lambda, Google Cloud Functions, Azure Functions, OpenWhisk Actions). The Event Gateway enables building large serverless architectures in a unified way across different providers.

Background

SOA came along with a new set of challenges. In monolithic architectures, it was simple to call a built-in library or rarely-changing external service. In SOA it involves much more network communication which is not reliable. The main problems to solve include:

  1. Where is the service deployed? How many instances are there? Which instance is the closest to me? (service discovery)
  2. Requests to the service should be balanced between all service instances (load balancing)
  3. If a remote service call failed I want to retry it (retries)
  4. If the service instance failed I want to stop sending requests there (circuit breaking)
  5. Services are written in multiple languages, I want to communicate between them using the best language for the particular task (sidecar)
  6. Calling remote service should not require setting up new connection every time as it increases request time (persistent connections)

The following systems are solutions those problems:

The main goal of those tools is to manage the inconveniences of network communication.

Microservices Challenges & FaaS

The greatest benefit of serverless/FaaS is that it solves almost all of above problems:

  1. service discovery: I don't care! I have a function name, that's all I need.
  2. load balancing: I don't care! I know that there will be a function to handle my request (blue/green deployments still an issue though)
  3. retries: It's highly unusual that my request will not proceed as function instances are ephemeral and failing function is immediately replaced with a new instance. If it happens I can easily send another request. In case of failure, it's easy to understand what is the cause.
  4. circuit breaking: Functions are ephemeral and auto-scaled, low possibility of flooding/DoS & cascading failures.
  5. sidecar: calling function is as simple as calling method from cloud provider SDK.
  6. in FaaS setting up persistent connection between two functions defeats the purpose as functions instances are ephemeral.

Tools like Envoy/Linkerd solve different domain of technical problems that doesn't occur in serverless space. They have a lot of features that are unnecessary in the context of serverless computing.

Service Discovery in FaaS = Function Discovery

Service discovery problems may be relevant to serverless architectures, especially when we have a multi-cloud setup or we want to call a serverless function from a legacy system (microservices, etc...). There is a need for some proxy that will know where the function is actually deployed and have retry logic built-in. Mapping from function name to serverless function calling metadata is a different problem from tracking the availability of a changing number of service instances. That's why there is a room for new tools that solves function discovery problem rather than the service discovery problem. Those problems are fundamentally different.

event-gateway's People

Contributors

absoludity avatar ac360 avatar alexdebrie avatar baniol avatar bdq avatar bencevans avatar brianneisler avatar ganeshvlrk avatar horike37 avatar ijin avatar jacobsauerhoefer avatar mthenw avatar nikgraf avatar paulxuca avatar plfx avatar pmuens avatar raeesbhatti avatar rafalwilinski avatar rupakg avatar scottbrenner avatar sebito91 avatar shortjared avatar spacejam avatar worldsoup avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

event-gateway's Issues

Implement event-driven data architecture (libkv, embedded etcd)

We discussed it with @spacejam (https://github.com/serverless/company/pull/338#issuecomment-303724238). The best option to start and not get involved in difficult dist sys problem is to use existing consistent data stores for storing instance state.

This task is about implementing first integration. I think it makes sense to start with interface definition (probably based on https://github.com/serverless/gateway/blob/master/db/db.go) and implementation for DynamoDB.

Logging

Should we use logfmt? Or something different? I think that this decision should be made early so it's easier to apply the same pattern everywhere.

Define internal data model for the gateway

  • function endpoint, including cloud provider required invocation info
  • named function, mapping to several function endpoints, with weights for load balancing
  • topics
  • pub-sub, mapping from function input/output to topic, and topic to function name
  • external security config

implement basic HTTP endpoint calling function

@brianneisler need more info here

  • what is an url under which gateway accept events (http://.../<username>/<functionname> or /<functionname>
  • is HTTP request payload directly passed as event to Lambda function or is wrapped with some object? What is the structure of wrapping object?
  • what is the expected response object structure? Same as for API Gateway?

Support multiple CORS origins for sync subscriptions

This is a Feature Request

Ideally the gateway would support multiple headers to be configured, and perform a request-time match for us returning only one CORS header since only one is supported by W3C https://www.w3.org/TR/cors/#resource-requests.

functions:
  hello:
    handler: handler.hello
    events:
      - http:
          path: user/create
          method: get
          cors:
            origins:
              - https://origin1.com
              - https://origin2.com

Related issue from framework serverless/serverless#2476

Implement basic subscription feature

It should allow attaching an event to a function.

It can be implemented as a part of function discovery, where during the function registration source events can be defined

Example:

{
	"id": "welcome-email",
	"instances":[{
		"provider": "aws-lambda",
		"originId": "arn:aws:lambda:us-east-1...",
		"region": "us-east-1"
	}],
        "events": [{
            "id": "userCreated",
            "retry": false
            ...
        }]
}

or as a separate endpoint POST /subscriptions

Example:

{
    "functionId": "welcome-email",
    "eventId": "userCreated",
    "retry": false
    ...
}

retry is an example field. I should start with something simple, at-least-once delivery semantic.

Implement first connector

I would start with something simple like Kinesis RMQ. Implementation should include import feature allowing reacting on events.

cache deserialized functions

Right now, we are deserializing function config from JSON on every invocation. We should maintain a cache of deserialized configuration which is maintained by the Created, Modified, and Deleted callbacks.

highlight high-level use cases at top of readme

Focus: what does this solve?

Explanatory graphic, maybe showing pub-sub - the ascii diagram is not clear enough

Description of how it works in a paragraph.

  1. starting up in local mode
  2. basic configuration
  3. hitting a function on aws
  4. creating a topic
  5. creating a subscriber
  6. creating a publisher
  7. triggering the publisher and observing the effect

restart watchRoot at a randomized interval to reconcile lost updates

Watching for updates is not enough to detect updates. Sometimes there are tcp issues, and all sorts of other random bugs can pop up to cause an update to go unseen by a process waiting on a watch to fire. To mitigate this, we just need to add a timeout chan to the select loop of processEvents in db.go which returns false when selected. The timeout channel should be randomized to prevent a thundering herd effect when each gateway reconnects.

Research access role support

The idea is to be able to call functions deployed in users' account from our account.

For AWS there are two options:

  • use role delegation (user's AWS account allows role from our account to manage user's resources)
  • use API credentials

We want to integrate this with the framework so it's transparent to the user.

It requires Gateway to accept accessRole param in function instance object.

[Metrics] Measure all the things!

Now that we have prometheus wired up, let's expand the things we're measuring:

  • counters for all errors (although maybe Fatal's are less useful because Prometheus is pull-based and will probably not retrieve it in time)
  • latency histogram for Get's to the config database
  • latency histogram for Put's to the config database

Investigate existing data access patterns.

Bugs and human coordination issues increase dramatically to the extent that state exists in multiple places. https://github.com/serverless/services-service stores data and other components will need to coordinate about state transitions (configuration etc...). It would be wonderful if we could do both simultaneously with a reactive storage architecture. My initial thought is to take heavy inspiration from the k8s storage model, where multiple components treat etcd as a reliable, persistent configuration store + pubsub, as different components can "watch" directories that they are interested in and react to changes in them. This work is to determine any hurdles that may stand in the way of moving that way.

user migration rough plan

eventually we may have a high-value customer who is trashing the performance of a system that is used by a large number of other customers. we should think about how to migrate users in this system from one cluster to another.

Fix flaky etcd test

The local etcd test fails occasionally with a 60 second timeout for receiving the first update written to the database.

Local experience?

What will the local development experience look like for a developer working on a serverless service that uses the gateway? I emphasize that i'm not talking about devs developing the gateway itself, but instead using the gateway as part of their serverless service

Some questions/thoughts

  • Is it possible to boot and run the gateway locally? (i'm pretty sure it is but here for posterity)
  • Is it possible to have a locally running version of the gateway tap in to events from another gateway (one running on our hosted service)?
    • We can't replicate all cloud infrastructure to run locally. However, we can enable developers to connect their local development experience in to cloud inf events which is a good replacement.
  • Could the gateway binary be embedded in to the framework so that we could offer a better local dev experience without having to install a plugin.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.