Giter Site home page Giter Site logo

checkout's Introduction

Checkout -- an actor-based service composition

This subset of a larger application demonstrates Project Orleans actors used to compose and manage an e-commerce cart. The hosting silos are not shown, so this code won't run as is. You can compile it though, once the NuGet packages download and install.

Overview

I became interested in actors when I discovered Microsoft's Project Orleans last summer. Abstracting away the difficulty of low-level distributed cloud applications in Azure was compelling, and I rewrote an e-commerce app to take advantage of Orleans' scalable, resilient silo/grain architecture.

I like that Orleans silos can hold response time at >90% CPU utilization (says Microsoft, I haven't tested yet) and once built the silos are easy to deploy onto Azure.

Actors as a gateway to Azure microservices

Virtual machines are today's most popular cloud platform, but Mark Russinovich has already said that Microsoft will transition the Azure web role/worker role PaaS platform into a more microservice-oriented form.

Actors' encapsulation, inherent scalability, and fault-tolerance seem like a natural form to run on a microservices platform.

Code highlights

In this application grains prefixed ServiceGrain interact directly with third party services. They are all REST-based packages from NuGets except Avalara who don't publish NuGets yet. .NET or WCF connections work fine too. Grains prefixed Grain aggregate service grains with business logic to compose complex services.

The unit tests run against grains running in live silos, so the release progression goes from development grain/silo to production grain/silo.

At this moment versioning grains requires a full rebuild of all the silos (as opposed to a rolling upgrade) but I am told this will change. Smart people have developed grain versioning techniques that they say work fine in production. The approach is to use OnActivateAsync() (see below) to compare the grain's version with the current version, and upgrade the schema of that grain if its version is out of date.

ServiceGrainBingLocation shows a from-scratch REST client. The other service grains use HTTP connections that are built in to their respective SDKs.

Serializing grain-to-grain communication

Because actors communicate by passing messages, types passed between grains have to be serializable. Many .NET classes are not serializable and can't be used for grain-to-grain communication. A solution is to create a covering class that the grains can use, then copy its properties into the non-serializable class.

The IServiceGrainSendGrid interface and its companion grain ServiceGrainSendGrid are a good example. The SendGridMessage class comes with the SendGrid SDK, and it uses System.Net.Mail.MailAddress, which is not serializable. The EmailMessage class is, and passes the email message to the SendGrid service grain, which copies its properties into the SendGridMessage class and sends it off to SendGrid.

Actors are asynchronous

Actors can scale because they are single-threaded internally, and their methods are asynchronous. In .NET, that means all grain methods are async methods that return Task or Task<T>. You can see examples of both in GrainCart.

Overriding the OnActivateAsync() grain method is a way to initialize a grain or read its state from a persisted state provider. ServiceGrainAvalara and ServiceGrainSendGrid demonstrate initialization, and GrainCart demonstrates reading state from a provider, if that state exists.

Conclusion

Microservice platforms promise resilient, automatically scalable service compositions that can stay up, seek and serve demand, respond to outages, and use cloud computing dollars as efficiently as possible.

For application architectures that can use them effectively, actors are a powerful and convenient way to compose and deliver microservice-based applications.

Credits and thanks

Sergey Bykov and Gabriel Kliot have been very generous with their time and have been instrumental in helping me to understand and build code using this very cool technology.

checkout's People

Contributors

toddshelton avatar

Watchers

 avatar  avatar

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.