Zewdie Midterm Study Guide
Zewdie Midterm Study Guide
● Services - any software function that carries out a business task or process (placing an
order, shipping an order, whatever). Any useful functionality exposed by a system.
○ Services can be used to share functions across different application
○ Services can be clients or servers
○ Usually found on another machine
● Distributed Object Technologies
○ Before RESTful services, services were language dependent and proprietary.
○ Based on Proxy/Stub technology. A lot harder to use
○ Client has a proxy, goes across the network to the stub, and gets customer
objects. For a distributed object.
○ Moral of the story - convoluted, confusing, and sucks.
○ Usually implemented on TCP ports that were not standardized across vendor
implementation. Sucks. Nothing universally standardized.
○ Closed Distributed Computing Representation
■ A closed graph. Only works with one vendor’s system - you cannot
expose it to anyone else but people using your vendor’s system.
● Service Oriented Architecture (SOA)
○ Definition - Style of design that guides all asploosects of creating and using
business services throughout their lifecycle.
○ SOA - paradigm for organizing and utilizing distributed capabilities under control
of different ownership domains.
○ The idea of how to expose services to people outside of one vendor.
○ Underlying structure supporting communication between services.
○ Defines how two computing entities such as programs interact so one does work
for another.
○ Service Provider → Service Broker → Service Consumer
■ Provider publishes services to broker.
■ Consumer requests broker for services.
■ Through broker, interaction.
○ Design paradigm - business functions are defined as services and logically
managed.
○ Many ways of implementing it - including REST, SOAP/WSDL. With Java
RMI, .Net Remoting.
○ Protocol independence - consumers can communicate with the service in
different ways.
○ There can be different brokers for the same services - you can use a different
broker to get the same service, because the request might be implemented
differently - works across REST and SOAP, for example.
● Web Services
○ refer to software functions that can be invoked by leveraging HTTP as a simple
transport protocol over which data is carried, or by using HTTP as a complete
application protocol that defines the semantics for service behavior.
■ Can be done with HTTP as a simple transport protocol - data is just
carried this way - or can be done as complete application protocol -
RESTful services rely completely HTTP.
○ Terms
■ Consumer - Service Requestor.
■ Server - provider who responds to request
● Why Web Services
○ Conceived to address shortcomings of distributed object technologies.
○ Provide means to integrate disparate systems and expose reusable business
functions over HTTP.
○ Broad reach is possible because they rely on open and interoperable standards
independent of the underlying technology.
■ Language independent - nonproprietary
○ Use HTTP and leverage data interchange standards like XML and JSON and
common media types.
■ Open standards payload
■ Standard serialization/deserialization
○ Due to their inherent interoperability and simplicity, web services facilitate the
creation of complex business processes through service composition (creating
compound services by assembling simpler services into workflow)
○ Make it easy to resuse and share services across mobile, desktop, and web
apps.
● Frameworks and Standards for Web Services Programming
○ Client Apps
○ Service layer
○ Domain Layer - Domain Models, Table Modules, Workflows, Code Libraries,
Commercial Packages, Legacy Apps
○ Data Sources - Databases, Files, Multimedia, Middleware
■ Above are layers.
● Basic Web Services Standards
○ JSON, XML, XML Schema Definition Language (XSD), Web Services
Description Language (WSDL), XPath, XSLT
● JavaScript Object Notation
○ Lightweight data-interchange format. Easy all around.
○ Text format that is completely language independent.
● Extensible Markup Language XML
○ Defines rules for encoding documents in a format that is both human and
machine readable.
○ Use it for lots of stuff - but you can also use it to send data. Can also be used for
configuration and layout.
○ More like HTML with tags
● TCP/IP Protocol
○ Application
○ Transport
○ Internet
○ Network Interface
■ Above are layers
○ TCP - Transmission Control Protocol
■ Breaks data into IP packets before they are sent, and assemble them
when they arrive.
■ Post office
○ IP - Internet Protocol
■ Takes care of comm with other computers.
■ Responsible for sending and receiving data packets over the internet.
■ Post person
● HTTP Protocol
○ Hypertext Transfer Protocol
■ HTTP takes care of the comm between a web server and browser.
■ Used for sending requests to a web client - returns web content.
○ HTTP has a very rich vocab in terms of
■ Verbs
■ URIs
■ Request and Response Headers
■ Internet Media Types
■ HTTP Request and Response codes, etc.
● HTTP Server Methods
○ POST
○ GET
○ PUT
○ DELETE
● Typical HTTP URI
○ http://bookstorecom/shop/book?title=XYZ&pubYear=2013
○ Protocol identifies the transport scheme that will be used to process and respond
to the request (http)
○ (bookstore.com) Identifies the server of the address resource
○ (shop/book?) Path in server directory
○ (title=XYZ&pubYear=2013) The actual request at the path
○ URI is always unique, or the server would have overriding requests - a mess.
● Web Services Frameworks
○ SOAP/WSDL/POX Frameworks
■ Java API for XML web services (JAX-WS)
■ Apache (CXF)
■ Microsoft’s Windows Communication Foundation (WCF)
○ REST Frameworks
■ Java API for RESTful Web Services (JAX-RS)
■ Microsoft’s WCF
● Web Service API Styles
○ API - a set of functions that one program makes available to other programs so it
can talk to it directly.
■ OS API’s
■ App API’s
■ website…
○ Three Types of API’s
■ RPC (Remote Procedure Call)
■ Message API
■ Resource API
○ RPC - Defines messages that identify the remote procedures to execute and also
include a fixed set of elements that map directly into the parameters of remote
procedures - remote function invocation
○ Message API Style
■ How clients send commands, notifications, or other information to remote
systems over HTTP while avoiding direct coupling to remote procedures?
● Define messages that are not derived from teh signatures of
remote procedures.
● May carry information on specific topics, tasks to execute, and
events.
● Have the client send the message to designated URI - executes
correct procedure based on message
○ Resource API Style
■ Uses standardized Server Methods
■ How can client manipulate data managed by a remote system, avoid
direct coupling to remote procedures, and minimise the need for domain-
specific API?
● Assign all procedures, instances of domain data, and files a URI.
● Leverage HTTP as a complete application protocol to define
standard service behaviors.
● Exchange information by taking advantage of the standard sized
media types and status codes when possible
○ REST is simpler and scales easily. Creates permeability, promotes co-creation.
Easy, everyone uses it.
○ Take decision choosing API style seriously - hard to switch.
● 12 Factor App
○ Used by Heroku that outlines the best practices to design and develop web-
based applications
○ Good to do. Makes it easy to migrate to cloud.
○ 12 FACTORS (http://12factor.net | http://www.clearlytech.com/2014/01/04/12-factor-apps-plain-english/)
■ Codebase
■ Dependencies
■ Config
■ Backing Services
■ Build, Release, Run
■ Processes
■ Port Binding
■ Concurrency
■ Disposability
■ Dev/Prod Parity
■ Logs
■ Admin Processes
○ Codebase - ‘One code base tracked in revision control, many deploys’
■ Common code shared between multiple apps should be externalized in
jars
■ Can be deployed in multiple environments and local dev machines
■ One codebase in a VCS.
○ Dependencies - “Explicitly declare and isolate dependencies”
■ Explicitly declare and isolate dependencies
■ Never rely on the implicit presence of system-wide packages, tools, and
libs
■ Use management tools like Chef
○ Config - ‘Store config in the environment’
■ Config data should be stored in a different repo location from the code
and read by the code at runtime.
■ Config should be copied to the enviro at time of code deployment
■ Store configs in environmental variables
○ Backing Services - ‘Treat backing services as attached resources’
■ Treat backing services as attached resources
■ Attaching and detaching resources requires no code changes
■ Treat URLs as environmental variables stored in configs
■ Make no distinction between local and third party services (no distinction
between a service run locally or on the cloud).
○ Build, Release, Run - “Strictly separate build and run stages’
■ Build - Transforms codebase into executable
■ Release - Combines a build with configuration to create a release
■ Run: runs the released app in an execution environment
○ Processes - ‘Execute the apps as one or more stateless processes’
■ Do not carry over state between transitions
■ Session state or persisted data must be stored in an attached services
such as a cache
■ Store intermediate data, so if one service goes down, possibly another
instance can pick it up and continue.
■ Enables concurrency, scales horizontally, fault tolerant.
○ Port Binding - ‘Export services via port binding’
■ The idea is that, just like all the backing services you are consuming, your
app also interfaces to the world using a simple url.
■ Processes communicate by binding to a port and listening to request.
■ Usually you get this for free because your app is already presenting itself
through a web-server.
■ One app can become the backing service for another app, by providing
the URl to the backing app as a resources handle in the config for the
consuming app.
○ Concurrency - “scale out via the process model’
■ You’ll be able to do more stuff concurrently, by smoothly adding additional
servers, or additionally CPU/RAM and taking full advantage of it through
the use of more of these small, independent processes.
■ Scale horizontally by spawning more app processes.
○ Disposability - ‘Maximize robustness with fast startup and graceful shutdown’
■ Processes can be started or stopped at any time.
■ Rapid startup.
■ Fault-tolerant and rapid-release
■ No mandatory ‘cleanup task’ when the apps shut down
○ Dev/Prod Parity - ‘Keep dev, staging, and production as similar as possible’
■ Continuous deployment - small gap between development and production
■ Backing services parity dev/prod environment
■ Use tools such as Vagrant for dev to manage developer’s local virtual
server - local config rewrites
○ Logs - ‘Treat logs as event streams’
■ Apps should never manage the routing and storing of its output stream.
■ Processes should write all logs to stdout as a stream.
■ Execution environment captures and routes the log stream
○ Admin Processes - ‘Run admin/management tasks as one-off processes’
■ You’ll want to do lots of one-off administrative tasks once you have a live
app.
■ Having console access to a production system is a critical administrative
and debugging tool, and every major language/framework provides it.
■ They run against a release, using the same codebase and config as any
process run against that release.
■ Admin code must ship with app code to avoid sync issues.
○ Conclusion
■ Use declarative formats for setup automation, to minimize time and cost
for new devs joining project.
■ Have a clean contract with the underlying operating system, offering max
portability between execution env.
■ Are suitable for deployment on modern cloud platforms
■ Minimize divergence between development and production, enabling
continuous deployment for max agility.
■ And can scale up without significant changes to tooling, architecture, or
development practices
○ Principles of Web Service/API Design
■ Encapsulation
● Services hide their implementation detail
● Client should not know and not make any assumptions.
● When domain layer change, client should not be impacted.
● Service can be swapped as long as the API remains the same
■ Service Contract
● An agreement that specifies how clients and services interact.
● Contract
○ Pre-conditions: what must be true befroe service can be
called
○ Post-condtions: what must be true after service is
completed
○ QoS: quality of services such as performance (latency),
security, privacy
■ Description of API
● Should be unambiguous, formal representations of:
○ A service’s functionality
○ A service’s non functional attributes
○ A user’s needs and preferences
■ Autonomy
● Consistent and reliable outcomes are more likely when the service
controls its own execution and has fewer dependencies.
● Reduce relying on distributed services so that the outcome will not
be partially determined.
■ Partial Failures
● Involves a remote service that involves networks
● Clients must be prepared for services to fail
● Both service and clients must be ready to handle when network
fails and saturated with traffic.
■ Completeness
● Loose coupling
● Implementation neutrality
● Flexible configurability
● Persistence
● Granularity
○ Principles of Web Service/API Designface - Words of Wisdom
■ Multiple variables to consider.
■ Going extreme on one may create problem on others.
■ Need to be looking all together and consider trade off
■ Not all come without consequences
● HTTP vs HTTPS
○ HTTPS creates secure channel on insecure network.
○ Protects from eavesdroppers and man in the middle attacks, and the server is
trusted.
○ Encrypts an HTTP message prior to transmission, and decrypting a message
upon arrival.
○ HTTPS is not a seperate protocol, but refers to use of ordinary HTTP overa an
encrpytred Secure Sockets Layer (SSL)
● Filters, Interceptors, and Invokers
○ It is possible to intercept and modify the inbound and outbound calls with the help
of CXF JAX-RS filters and or CXF Interceptors
○ Filters - often necessary to pre- or post-process some requests according to a
number of rquirement.
○ CXF filter which will introspect the resource class, input or output meessage, the
operation which was invoked and modify the request or response accordingly.
○ JAX-RS filters can be thought of as additional handlers.
● Configuring JAX-RS Services
○ JAX-RS services can be configured programmatically using
■ Spring
■ CXFNonSpringJAXRSServlet
■ Or using configuration files