Showing posts with label serverless. Show all posts
Showing posts with label serverless. Show all posts

May 12, 2018

[design][microservice] The hardest part of microservices is your data

Watch note for The hardest part of microservices is your data


slides:
https://www.slideshare.net/ceposta/the-hardest-part-of-microservices-your-data
  • Microservices is about optimizing for SPEED.
  • Manage (aka. reduce) dependencies.
  • Data is a major dependency.
  • Focus on domain models, not data models
  • Stick with these conveniences as long as you can.
  • A microservice has its own database
  • We need to understand something about the data inside our services and the data outside our services
    • Thus, we are building a distributed system, thus, beware of 
      • network latency, 
      • network partition
  • Plan for failures.
    • Build concepts of time, delay, network, and failures into the design as a first-class citizen
  • How do you “read” data and how do you “update” data.
  • Performance: N+1 Query Problem
  • For our reads and writes, we need some "consistency"
  • We need reads and writes. But we expect failures. 
    • CAP tells us to pick 2: Consistency, Availability, Partition Tolerance
    • CAP is a bad way to think about this.
  • Consistency model
    https://en.wikipedia.org/wiki/Consistency_model
  • What consistency model do you need, depending on what role you’re playing?

[design] Serverless Architecture (FaaS)

Watching note for Serverless: the Future of Software Architecture • Peter Sbarski

cross reference:
Designing distributed system

Function as Service (execute custom code)
Backend as a Service (3rd-party services)

Adopt

  • Pipelines as code
  • APIs as a product
  • Decoupling secret management from source code
  • Hosting PII data in the EU
  • Legacy in a box
  • Lightweight architecture decision records
  • Progressive web applications
  • Prototyping with invision and sketch
  • Serverless architecture

e.g
AWS Lambda for compute
S3 for storage


Principles of Serverless Architecture

  • Use a code-execution compute service to run code on demand
  • Write single-purpose statelesss functions
  • Design push-based, event-driver pipelines
  • Create thicker, more powerful front ends
  • Embrace third party services

Use a code-execution compute service to run code on demand

Do not run on a server.
Focus on function, not application update/upgrade
(e.g patch Apache web server etc.)

Compute as backend:
API-Gateway is needed for REST API


Compute as glue:
Act as Pipeline


Write single-purpose statelesss functions

Pure function
Only 0 or 1 transformation

Design push-based, event-driver pipelines

One event triggers another event.
e.g




e.g.
Use websocket, push based.

Create thicker, more powerful front ends

traditional way:


Changed way:


Embrace third party services

Benefits

  • time to market
  • scale effortlessly (deal with spikes traffic)
  • disruptive cost model
  • no more server to manage
  • versatile
  • lower cost
  • less code
  • easy to scale and flexible

Cons

  • Not for everyone
  • Service level and customization
  • Vendor lock-in
  • Decentralization

Architecture

Go for microservices
Use API-Gateway
https://www.algolia.com/ as search service