CS计算机代考程序代写 database Java cache JDBC asp.net SE457 Week 7 – gRPC, OSGi, Patterns

SE457 Week 7 – gRPC, OSGi, Patterns
Steven Engelhardt
DePaul University
Spring 2021
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 1 / 87

Table of Contents
1 Last Week
Last Week Review
2 Remote Service Technologies gRPC
Summarizing Web Service Technologies
3 SOA Without Web Services OSGi
4 SOA Patterns Introduction
Foundational
Performance, Scalability, and Availability Security and Manageability
Message Exchange
Service Consumer
Service Integration
Antipatterns
5 Wrap-Up
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 2 / 87

Table of Contents
1 Last Week
Last Week Review
2 Remote Service Technologies gRPC
Summarizing Web Service Technologies
3 SOA Without Web Services OSGi
4 SOA Patterns Introduction
Foundational
Performance, Scalability, and Availability Security and Manageability
Message Exchange
Service Consumer
Service Integration
Antipatterns
5 Wrap-Up
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 3 / 87

Last Week
• REST case studies (GitHub, Stripe, Okta, Stack Exchange) • OData
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 4 / 87

Table of Contents
1 Last Week
Last Week Review
2 Remote Service Technologies gRPC
Summarizing Web Service Technologies
3 SOA Without Web Services OSGi
4 SOA Patterns Introduction
Foundational
Performance, Scalability, and Availability Security and Manageability
Message Exchange
Service Consumer
Service Integration
Antipatterns
5 Wrap-Up
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 5 / 87

Table of Contents
1 Last Week
Last Week Review
2 Remote Service Technologies gRPC
Summarizing Web Service Technologies
3 SOA Without Web Services OSGi
4 SOA Patterns Introduction
Foundational
Performance, Scalability, and Availability Security and Manageability
Message Exchange
Service Consumer
Service Integration
Antipatterns
5 Wrap-Up
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 6 / 87

gRPC
• A high-performance, open source universal RPC framework
• Uses Protocol Buffers as a data serialization format by default, which
is more efficient than JSON
• Can auto-generate client stubs in several languages
• Used by Netflix, Square, Cisco, and many others
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 7 / 87

Simple Example – Service Definition
syntax = “proto3”;
option java_multiple_files = true;
package edu.depaul.se457.grpc;
message HelloRequest {
string firstName = 1;
string lastName = 2;
}
message HelloResponse {
string greeting = 1;
}
service HelloService {
rpc hello(HelloRequest) returns (HelloResponse);
}
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 8 / 87

Simple Example – Service Implementation
package edu.depaul.se457.grpc.server;
import edu.depaul.se457.grpc.HelloRequest;
import edu.depaul.se457.grpc.HelloResponse;
import edu.depaul.se457.grpc.HelloServiceGrpc.HelloServiceImplBase;
import io.grpc.stub.StreamObserver;
public class HelloServiceImpl extends HelloServiceImplBase { @Override
public void hello(
HelloRequest request, StreamObserver responseObserver) { System.out.println(“Request received from client:\n” + request);
String greeting = new StringBuilder().append(“Hello, “) .append(request.getFirstName())
.append(” “)
.append(request.getLastName())
.toString();
HelloResponse response = HelloResponse.newBuilder() .setGreeting(greeting)
.build();
responseObserver.onNext(response);
responseObserver.onCompleted(); }
}
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 9 / 87

Simple Example – Hosting Service
package edu.depaul.se457.grpc.server; import java.io.IOException;
import io.grpc.Server;
import io.grpc.ServerBuilder;
public class GrpcServer {
public static void main(String[] args) throws IOException, InterruptedException {
Server server = ServerBuilder.forPort(8080) .addService(new HelloServiceImpl()).build();
System.out.println(“Starting server…”); server.start(); System.out.println(“Server started!”); server.awaitTermination();
} }
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 10 / 87

Simple Example – Client
package edu.depaul.se457.grpc.client;
import edu.depaul.se457.grpc.HelloRequest; import edu.depaul.se457.grpc.HelloResponse; import edu.depaul.se457.grpc.HelloServiceGrpc;
import io.grpc.ManagedChannel;
import io.grpc.ManagedChannelBuilder;
public class GrpcClient {
public static void main(String[] args) throws InterruptedException {
ManagedChannel channel = ManagedChannelBuilder.forAddress(“localhost”, 8080) .usePlaintext()
.build();
HelloServiceGrpc.HelloServiceBlockingStub stub
= HelloServiceGrpc.newBlockingStub(channel);
HelloResponse helloResponse = stub.hello(HelloRequest.newBuilder() .setFirstName(“Baeldung”)
.setLastName(“gRPC”)
.build());
System.out.println(“Response received from server:\n” + helloResponse); channel.shutdown();
} }
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 11 / 87

Main Usage Scenarios
• Efficiently connecting polyglot services in microservices style architecture
• Connecting mobile devices, browser clients to backend services • Generating efficient client libraries
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 12 / 87

Core Differentiating Features
• Idiomatic client libraries in 10 languages
• Highly efficient on wire and with a simple service definition framework
• Bi-directional streaming with http/2 based transport
• Pluggable auth, tracing, load balancing and health checking
• Nimble and lightweight, which makes it appropriate for mobile and IoT clients
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 13 / 87

Closing Thoughts
• Shares a number of similarities with SOAP: • Separates definition of contract
• Services are quick to develop
• Most commonly used by organizations which create both the client and the server, as opposed to over the public Internet by disparate client teams
• Anecdotally, seems to be extremely popular in organizations for their internal (micro)service platforms
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 14 / 87

Table of Contents
1 Last Week
Last Week Review
2 Remote Service Technologies gRPC
Summarizing Web Service Technologies
3 SOA Without Web Services OSGi
4 SOA Patterns Introduction
Foundational
Performance, Scalability, and Availability Security and Manageability
Message Exchange
Service Consumer
Service Integration
Antipatterns
5 Wrap-Up
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 15 / 87

Other Notable Technologies
• GraphQL
• Facebook Thrift
• Cross-language RPC framework • Netflix Ribbon
• Multi-protocol IPC library • Google Borg
• Predecessor to Kubernetes
• Microsoft WCF, ASP.NET Web API • Oracle REST Data Services (ORDS) • (Lots more)
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 16 / 87

Comparing Technologies
Transport
Request Content- Type
Response Content- Type
HTTP Transport Utilization
Data Model Defini- tion Language
Contract Definition Lagnuage
SOAP
HTTP, SMTP, FTP, others
XML XML None XSD WSDL
REST HTTP only
Any (usually JSON or XML)
Any (usually JSON or XML)
Full
No ubiquitous standard
No ubiquitous standard (but there’s WADL, RAML, Swagger, etc.)
OData V4
HTTP only
Atom-XML or JSON
Atom-XML or JSON
Full
OData Metadata Document
OData Service Document
gRPC
HTTP/2 Protobuf Protobuf
Minimal
Protobuf message Protobuf service
Steven Engelhardt (DePaul University)
SE457 Week 7 – gRPC, OSGi, Patterns
Spring 2021
17 / 87

Comparing Technologies
Service Discovery
SOAP
UDDI
JAX-WS
Strong tool support; comprehensive WS* standard set
Complex, inefficient, rarely used for new services nowadays
REST
No ubiquitous standard
JAX-RS Simple, efficient
May be round-trip heavy; no standard discoverable Metadata
OData V4
No ubiquitous standard
Apache Olingo
Standard way of supporting SQL-like querying on RESTful APIs
Access patterns may be unpredictable and thus hard to implement well; query language not as powerful as GraphQL; niche
gRPC
External (e.g. etcd)
gRPC
Strong tool support; high-performance
Rarely used by consumers unrelated to service
Example brary
Java
Li-
Strengths Weaknesses
Steven Engelhardt
(DePaul University)
SE457 Week 7 – gRPC, OSGi, Patterns
Spring 2021
18 / 87

Back to SOA Design Principles
Standardized Contract-First Design
Loosely coupled
Non-essential ser- vice information is abstracted
SOAP
Rigid, well-specified contract
Somewhat Usually
Limited
REST
Loose, perhaps ill-specified contract
Somewhat Usually
Somewhat limited
OData V4 Loose contract
More
Service must support somewhat varied usage patterns
Somewhat limited
gRPC
Rigid, well-specified contract
Somewhat Usually
Limited
Reusable diverse, dictable clients
across unpre-
Steven Engelhardt (DePaul University)
SE457 Week 7 – gRPC, OSGi, Patterns
Spring 2021
19 / 87

Table of Contents
1 Last Week
Last Week Review
2 Remote Service Technologies gRPC
Summarizing Web Service Technologies
3 SOA Without Web Services OSGi
4 SOA Patterns Introduction
Foundational
Performance, Scalability, and Availability Security and Manageability
Message Exchange
Service Consumer
Service Integration
Antipatterns
5 Wrap-Up
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 20 / 87

Table of Contents
1 Last Week
Last Week Review
2 Remote Service Technologies gRPC
Summarizing Web Service Technologies
3 SOA Without Web Services OSGi
4 SOA Patterns Introduction
Foundational
Performance, Scalability, and Availability Security and Manageability
Message Exchange
Service Consumer
Service Integration
Antipatterns
5 Wrap-Up
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 21 / 87

Background
• You can do SOA without web services
• SOA is building applications by creating autonomous components called services. Each service exposes business processes and behavior through contracts, which are composed of messages and discoverable addresses called endpoints.
• Nothing in this statement says that the autonomous components must be separated by a network or process boundary.
• SOA is largely about minimizing complexity by decoupling blocks of a system
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 22 / 87

Reducing Complexity by Limiting Communication Potential
• One simplistic way to quantitatively measure complexity is by the square of the number of links within a module
• The left module has complexity 92 = 81, the right has complexity 32 + 62 = 45
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 23 / 87

Principles of Package Cohesion
• Reuse-release equivalence principle (REP) – The unit of reuse is the unit of release.
• Common-reuse principle (CRP) – Classes that aren’t reused together should not be grouped together.
• Common-closure principle (CCP) – Classes that change together belong together.
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 24 / 87

Principles of Package Cohesion
• Acyclic dependencies principle (ADP) – The dependency structure between packages must not contain cyclic dependencies.
• Stable-dependencies principle (SDP) – The dependencies between packages should be in the direction of the stability of the packages. A package should only depend upon packages that are more stable than it is.
• Stable-abstractions principle (SAP) – Packages that are maximally stable should be maximally abstract (i.e. public Module Interfaces). Unstable packages should be concrete (Module implementations). The abstractness of a package should be in proportion to its stability.
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 25 / 87

Spell Checker Example
// In spellchecker.jar
import spellcheck.*;
public class TextEditor {
private SpellChecker checker;
public TextEditor() {
this.checker = new SpellChecker();
}
}
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 26 / 87

Reducing Coupling using IoC
// In spellchecker.jar
import spellcheck.*; public class TextEditor {
private SpellChecker checker;
public TextEditor() {
this.checker = new SpellChecker(); }
}
// In spellchecker.jar
import spellcheck.*; public class TextEditor {
private ISpellChecker checker;
public TextEditor(ISpellChecker checker) {
this.checker = checker; }
}
TextEditor editor =
new TextEditor(new MySpellChecker());
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 27 / 87

Remaining Coupling
• Everything (public) in spellchecker.jar is available to all other JARs
• Unless you do lots of careful work with class loaders, all JARs must share common versions of all shared dependencies (e.g. logging libraries)
• What if the spell checker can be loaded at runtime? How would the client discover it?
• What if we wanted to support upgrading a spell checker at runtime?
• What if spellchecker.jar was written by a third party?
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 28 / 87

Enter OSGi
• Dynamic module system for Java
• Contains a service registry so bundles can register themselves
• Supports installation, starting, stopping, updating, uninstalling bundles at runtime
• Used by Eclipse, GlassFish, IntelliJ, Jboss, NetBeans, Weblogic, others…
• Requires a OSGi container (e.g. Apache Felix, Eclipse Equinox)
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 29 / 87

Requirements & Capabilities
• An OSGi bundle is essentially a JAR plus a manifest
Bundle-Name: Hello World
Bundle-SymbolicName: org.wikipedia.helloworld Bundle-Description: A Hello World bundle Bundle-ManifestVersion: 2
Bundle-Version: 1.0.0
Bundle-Activator: org.wikipedia.Activator Export-Package: org.wikipedia.helloworld;version
=”1.0.0″
Import-Package: org.osgi.framework;version=”1.3.0″
• •
Everything in the JAR is hidden unless explicitly exported
An OSGi bundle explicitly lists the requirements it has on the environment and the capabilities it will provide to the environment
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 30 / 87

Bundle Versioning
• Bundles must use Semantic Versioning: Given a version number MAJOR.MINOR.MICRO.QUALIFIER, increment the:
• MAJOR version when you make incompatible API changes,
• MINOR version when you add functionality in a backwards-compatible
manner, and
• MICRO version when you make a bug fix but do not change the API • QUALIFIER version when you make a new build
• Following this versioning policy is essential to make package binding work correctly.
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 31 / 87

Bundle Version Ranges
• When importing, you can express a range of valid versions for a bundle
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 32 / 87

Example OSGi Contract
package org.osgi.service.log; •
public interface LogService
{
Note that this is purely an contractual interface! The implementation is not defined here.
}
// Log a message specifying a log level
public log(int level, java.lang.String message)
// Log an exception
public log(int level, java.lang.String message, java.lang
.Throwable exception)
// Log a message specifying the ServiceReference that generated it
public log(ServiceReference sr, int level, java.lang. String message)
// Log a message specifying the ServiceReference and exception
public log(ServiceReference sr, int level, java.lang. String message, java.lang.Throwable exception)
• Clients request this service by: Import-Package: org.osgi.service.log; version=”[1.3,2.0)”
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns
Spring 2021 33 / 87

Difference from JARs
• Explicit, encouraged separation of contract from implementation.
• Consumers do not choose implementations directly. Instead, bundles self-register themselves and platform chooses implementation based on requires / provides matching.
• Ability to start / stop / load / unload implementations at runtime
• Bundles are isolated; different bundles can use different versions of
the same dependency (e.g. a logging JAR)
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 34 / 87

OSGi Example Bundle
package com.javaworld.sample.service;
public interface HelloService {
public String sayHello(); }
package com.javaworld.sample.service.impl;
public class HelloServiceImpl implements HelloService {
public String sayHello() { System.out.println(“Inside HelloServiceImple.
sayHello()”);
return “Say Hello”;
} }
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 35 / 87

OSGi Example Bundle Manifest
# MANIFEST.MF
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: HelloService Plug-in
Bundle-SymbolicName: com.javaworld.sample.HelloService
Bundle-Version: 1.0.0
Bundle-Vendor: JAVAWORLD
Bundle-Localization: plugin
Export-Package: com.javaworld.sample.service
Import-Package: org.osgi.framework;version=”1.3.0″
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 36 / 87

Things to Note
• Even though HelloServiceImpl is public, it is not accessible from a OSGi consumer because it is not part of the Export-Package
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 37 / 87

Bundle Lifecycle
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 38 / 87

Using Activator to Handle Start / Stop
package org.wikipedia;
import org.osgi.framework.BundleActivator;
import org.osgi.framework.BundleContext;
public class Activator implements BundleActivator {
private BundleContext context;
@Override
public void start(BundleContext context) throws Exception {
System.out.println(“Starting: Hello World”);
this.context = context; }
@Override
public void stop(BundleContext context) throws Exception {
System.out.println(“Stopping: Goodbye Cruel World”);
this.context = null; }
}
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 39 / 87

OSGi and SOA
• A bundle’s Export-Package is essentially the contract that the service implements
• A bundle’s code is essentially the implementation of the service
• A bundle’s Import-Package is essentially the contract(s) that the service requires, without caring who will fulfill it
• Reification will happen at runtime by the OSGi platform
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 40 / 87

Benefits of OSGi
• Bundle reuse
• Bundles are isolated but ultimately execute in-process
• Provides autonomy with minimal loss of efficiency
• Allows dynamic servicing (e.g. upgrade long-running application without restart)
• Hard to do right, be careful!
• Natural fit for supporting customer plug-ins
• Jira, among many others, uses OSGi for this
• Widely used
• Mature
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 41 / 87

Drawbacks of OSGi
• Complex
• Relatively hard to learn
• Isolation is far from complete; a malicious OSGi module can perform all sorts of mischief
• May not play well with Spring Dynamic Modules
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 42 / 87

OSGi vs Java 9 Modules
• OSGi does its magic using Java classloaders, which breaks a key assumption: that every type can be found in at most one location.
• This is essential to support multiple versions of the same JAR
• Because of this, OSGi cannot easily be used to modularize the JDK
itself, so Java 9 introduced a separate technology: JPMS (aka Jigsaw)
• If you’re going to adopt modules, be sure to research and compare OSGi vs. JPMS
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 43 / 87

Table of Contents
1 Last Week
Last Week Review
2 Remote Service Technologies gRPC
Summarizing Web Service Technologies
3 SOA Without Web Services OSGi
4 SOA Patterns Introduction
Foundational
Performance, Scalability, and Availability Security and Manageability
Message Exchange
Service Consumer
Service Integration
Antipatterns
5 Wrap-Up
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 44 / 87

Table of Contents
1 Last Week
Last Week Review
2 Remote Service Technologies gRPC
Summarizing Web Service Technologies
3 SOA Without Web Services OSGi
4 SOA Patterns Introduction
Foundational
Performance, Scalability, and Availability Security and Manageability
Message Exchange
Service Consumer
Service Integration
Antipatterns
5 Wrap-Up
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 45 / 87

SOA Patterns
• An architectural pattern is a general, reusable solution to a commonly occurring problem in software architecture within a given context
• A SOA pattern is an architectural pattern that is related to service-oriented architecture
• For this section, I have selected a few notable patterns from the book SOA Patterns by Arnon Rotem-Gal-Oz
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 46 / 87

Table of Contents
1 Last Week
Last Week Review
2 Remote Service Technologies gRPC
Summarizing Web Service Technologies
3 SOA Without Web Services OSGi
4 SOA Patterns Introduction
Foundational
Performance, Scalability, and Availability Security and Manageability
Message Exchange
Service Consumer
Service Integration Antipatterns
5 Wrap-Up
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 47 / 87

Service Host – Problem
How can you easily configure services and avoid duplicating mundane tasks, such as setting listeners and wiring components, for each service?
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 48 / 87

Service Host – Solution
A service host is a framework or a complete component that performs some or all of the following functions:
• Lifecycle – Takes care
of instantiating services, recycling services on fault, in-place upgrades, and so on
• Configuration
– Reads and applies configuration
to hosted services, including configuration for security, contract policies, and ports
• Wiring – Performs
runtime setup of component wiring such
as binding a listener on a service’s endpoint
• Administration – Lets an administrator control the lifecycle of a hosted service and may also include monitoring capabilities
• Environment – Provides auxiliary services like logging, cache, database libraries (ODBC/JDBC), scheduler, and so on
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 49 / 87

Service Host – Details
• Java application servers like WebSphere, WebLogic, or Tomcat • Microsoft AppFabric
• Microsoft Service Host svchost.exe (Windows-managed services) • Kubernetes
• Custom service hosts to handle both cloud and on-prem installations
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 50 / 87

Active Service – Problem
• How can you increase service autonomy and handle temporal concerns?
• For example, if your service depends on the response from another service, how to you isolate your service from failures?
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 51 / 87

Active Service – Solution
Make the service an active service by implementing at least one active class, either on the edge, within the service, or both. Let the active class take care of temporal concerns and autonomy issues.
• An
active class is an object that may execute their own behavior without requiring method invocation.
• In other words, have background threads which perform cyclic events such as monthly billing, report generation, populating local caches from remote services on an independent schedule, etc.
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 52 / 87

Active Service – Details
• Imagine the shopping cart service at Amazon.
• In order to display a total cost, the shopping cart needs to know the
prices of each of the goods contained within the shopping cart.
• Rather than making real-time calls to the product price service, the shopping cart could instead maintain a local price cache which is updated once per hour. This way, the shopping cart service will not fail if the pricing service has failed.
• This approach may risk stale prices. However, we can accept this risk for the shopping cart total, and require the checkout process to retrieve the actual prices from the price service.
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 53 / 87

Table of Contents
1 Last Week
Last Week Review
2 Remote Service Technologies gRPC
Summarizing Web Service Technologies
3 SOA Without Web Services OSGi
4 SOA Patterns Introduction
Foundational
Performance, Scalability, and Availability
Security and Manageability Message Exchange
Service Consumer
Service Integration Antipatterns
5 Wrap-Up
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 54 / 87

Decoupled Invocation – Problem
How can a service handle normal request loads, peak request loads, and a continuous period of high load without failing?
• Provision servers for peak load?
• Use an elastic service at a public cloud?
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 55 / 87

Decoupled Invocation – Solution
• Separate replies from requests: acknowledge receipt at the service edge, put the request on a reliable queue, and then load-balance and prioritize the handler components that read from the queue.
• This is the same as the asynchronous operation examples from Week 7’s lecture about REST design
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 56 / 87

Gridable Service – Problem
How can you build services to handle computationally intense tasks in a scalable way?
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 57 / 87

Gridable Invocation – Solution
• Introduce grid technology to the service, via the Gridable Service pattern, to handle computationally intense tasks.
• Typically you need some way to divide the problem into subproblems that can be submitted to a cluster of machines
• Related technologies include Spark, Flink, Bistro, Globus, Gridbus, etc.
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 58 / 87

Service Watchdog – Problem
How can you increase availability by identifying and resolving problems and failures that are service-specific?
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 59 / 87

Service Watchdog – Solution
• Make the service actively monitor its internal state, act on potential trouble, try to heal itself, and continuously publish its status.
• The original term watchdog referred to a hardware device that counts down to 0, at which point it takes action, such as resetting the device. To prevent this reset, the application has to “kick the dog” before the timer runs out.
• A “panic and restart” fail-fast approach is often the right thing to do, particularly if your service host will automatically restart you.
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 60 / 87

Table of Contents
1 Last Week
Last Week Review
2 Remote Service Technologies gRPC
Summarizing Web Service Technologies
3 SOA Without Web Services OSGi
4 SOA Patterns Introduction
Foundational
Performance, Scalability, and Availability Security and Manageability
Message Exchange
Service Consumer
Service Integration
Antipatterns
5 Wrap-Up
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 61 / 87

Secured Message – Problem
How can you secure specific messages or message fragments that are exchanged between two or more services?
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 62 / 87

Secured Message – Solution
• Apply the Secured Message pattern to your messsages and add message-level security.
• This includes encryption, decryption, digital signatures, etc.
• This is applied to the messages themselves, not to the transport (e.g. TLS)
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 63 / 87

Secured Message – Details

1234-6789
9999-5678-9123-4567 123 02/05/1999 visa



123-456-789
10






FF5BDA12C3EE3A238FCD8721AE9354


123-456-789 10


Steven Engelhardt
(DePaul University)
SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 64 / 87

Service Firewall – Problem
How can you protect a service against malicious incoming messages and prevent information disclosure on outgoing messages?
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 65 / 87

Service Firewall – Solution
• Implement the Service Firewall pattern, intercept incoming and outgoing messages, and inspect them in a dedicated software or hardware component.
• This is often provided by your infrastructure provider (e.g. Azure Firewall, Azure NSGs) or as a third-party commercial product (e.g. Cisco, Palo Alto firwalls)
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 66 / 87

Service Monitor – Problem
How can you identify problems and faults in services, and then attend them, to ensure the overall business’s availability?
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 67 / 87

Service Monitor – Solution
• Apply the Service Monitor pattern, and deploy a centralized management point that will monitor services’ security, networks, QoS, policies, and any other governance-related issues.
• This is typically purchased as a third-party product. Examples include DataDog, New Relic, AppDyanmics, and Dynatrace.
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 68 / 87

Table of Contents
1 Last Week
Last Week Review
2 Remote Service Technologies gRPC
Summarizing Web Service Technologies
3 SOA Without Web Services OSGi
4 SOA Patterns Introduction
Foundational
Performance, Scalability, and Availability Security and Manageability
Message Exchange
Service Consumer
Service Integration
Antipatterns
5 Wrap-Up
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 69 / 87

Inversion of Communication – Problem
• How can you handle business events in an SOA?
• A business event is something that can occur at any time
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 70 / 87

Inversion of Communication – Solution
• Supplement SOA with event-driven architecture (EDA) – allow services to publish streams of events that occur in them instead of calling other services explicitly
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 71 / 87

Inversion of Communication – Details
• Complex event processing (CEP) frameworks allow you to treat events as a stream rather than isolated instances and apply complicated business logic on them
var loginRecords = engine.GetEventSource();
engine.AddQuery(() => from names in loginRecords. Stream
group names by names.Name
into logins
from login in logins
let next = logins.FirstOrDefault(t = > t.
LoginTime > login.LoginTime)
let nextNext = null == next ? null : logins.
FirstOrDefault(t => t.LoginTime > next.
LoginTime) where
!login.Successful && (null != next && !next .Successful) && (null != nextNext && ! nextNext.Successful)
select login, HanleAlert);
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 72 / 87

Saga – Problem
How can you reach distributed consensus between services without transactions?
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 73 / 87

Saga – Solution
Implement the Saga pattern and break the service interaction (the business process) into multiple smaller business actions and counteractions. Coordinate the conversation and manage it based on messages and timeouts.
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 74 / 87

Saga – Details
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 75 / 87

Table of Contents
1 Last Week
Last Week Review
2 Remote Service Technologies gRPC
Summarizing Web Service Technologies
3 SOA Without Web Services OSGi
4 SOA Patterns Introduction
Foundational
Performance, Scalability, and Availability Security and Manageability
Message Exchange
Service Consumer
Service Integration
Antipatterns
5 Wrap-Up
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 76 / 87

Reservation – Problem
How can you efficiently provide a level of guarantee in a loosely coupled manner while maintaining the autonomy and consistency of the services?
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 77 / 87

Reservation – Solution
Implement the Reservation pattern and have the services provide a level of guarantee on internal resources for a limited time. It has three responsibilities:
• Reservation – Making the reservation when a message that’s deemed “reserving” arrives.
• Validation – Making sure that a reservation is still valid before finalizing the process.
• Expiration – Marking invalid reservations when the conditions change.
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 78 / 87

Table of Contents
1 Last Week
Last Week Review
2 Remote Service Technologies gRPC
Summarizing Web Service Technologies
3 SOA Without Web Services OSGi
4 SOA Patterns Introduction
Foundational
Performance, Scalability, and Availability Security and Manageability
Message Exchange
Service Consumer
Service Integration
Antipatterns
5 Wrap-Up
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 79 / 87

Aggregated Reporting – Problem
How can you get efficient business intelligence and summary reports spanning the business, when the data is scattered and isolated in autonomous services?
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 80 / 87

Aggregated Reporting – Solution
Use the Aggregated Reporting pattern to create a service that gathers immediate copies of data from multiple services for reporting purposes.
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 81 / 87

Table of Contents
1 Last Week
Last Week Review
2 Remote Service Technologies gRPC
Summarizing Web Service Technologies
3 SOA Without Web Services OSGi
4 SOA Patterns Introduction
Foundational
Performance, Scalability, and Availability Security and Manageability
Message Exchange
Service Consumer
Service Integration
Antipatterns
5 Wrap-Up
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 82 / 87

Knot
• A Knot is an antipattern where the services are tightly coupled by hardcoded point-to-point integration and context-specific interfaces.
• Be very mindful about the communication patterns of services, and make sure that services only care about their immediate connections, and not about any dependencies of services they interact with
• Use the Inversion of Communications pattern, because service events are explicitly not addressed to any other service in particular
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 83 / 87

Nanoservice
• A Nanoservice is an antipattern where a service is too fine-grained. A nanoservice is a service whose overhead (communications, maintenance, and so on) outweighs its utility.
• Group related nanoservices into a larger service, or redistribute a nanoservice’s functionality among other services
[ServiceContract(Namespace = “http://Microsoft. WorkflowServices.Samples”)]
public interface ICalculator
{
[OperationContract()] int PowerOn(); [OperationContract()] int Add(int value); [OperationContract()] int Subtract(int value); [OperationContract()] int Multiply(int value); [OperationContract()] int Divide(int value); [OperationContract()]
} void PowerOff();
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 84 / 87

Transactional Integration
• Transactional Integration is an antipattern where transactions extend across service boundaries (they’re not isolated inside services).
• Keep ACID guarantees within a single service.
• Use Sagas for cross-service interactions, which don’t hold the same transactional guarantees as ACID transactions.
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 85 / 87

Table of Contents
1 Last Week
Last Week Review
2 Remote Service Technologies gRPC
Summarizing Web Service Technologies
3 SOA Without Web Services OSGi
4 SOA Patterns Introduction
Foundational
Performance, Scalability, and Availability Security and Manageability
Message Exchange
Service Consumer
Service Integration
Antipatterns
5 Wrap-Up
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 86 / 87

Next Steps
• Quiz 4 is available now. It will be due Tuesday, May 18 at 5:30PM.
• HW 4 is available now. It is due Tuesday, May 25 at 5:30PM.
• Research presentations are due Tuesday, June 1 at 5:30PM.
Steven Engelhardt (DePaul University) SE457 Week 7 – gRPC, OSGi, Patterns Spring 2021 87 / 87