SlideShare ist ein Scribd-Unternehmen logo
1 von 67
Downloaden Sie, um offline zu lesen
BASEL BERN BRUGG DÜSSELDORF FRANKFURT A.M. FREIBURG I.BR. GENF
HAMBURG KOPENHAGEN LAUSANNE MÜNCHEN STUTTGART WIEN ZÜRICH
Monolithen fit für die Zukunft trimmen
Warum Monolithen entstehen und wie Microservices helfen können,
die Biester zu bändigen
Anatole Tresch, Principal Consultant
Retrofitting monoliths for the future2 25.11.15
BIO
Anatole Tresch
●
Principal Consultant, Trivadis AG (Switzerland)
●
Star Spec Lead JSR 354
●
Technical Architect, Lead Engineer
●
PPMC Member Apache Tamaya
●
Twitter/Google+: @atsticks
●
atsticks@java.net
●
anatole.tresch@trivadis.com
●
Retrofitting monoliths for the future3 25.11.15
Agenda
●
Motivation
●
Microservices to our rescue!
●
How to get there?
●
Deep Dive:
●
Coupling
●
Breaking things up
●
API Design
●
Summary
Retrofitting monoliths for the future4 10.02.16
Motivation:
Why are monoliths a problem?
Retrofitting monoliths for the future5 10.02.16
Why are monoliths a problem?
●
Maintenance Costs
●
Time to Market
●
Performance
●
Stability and Robustness (forget Resilience!)
●
Flexibility (e.g. for Integration)
●
Vendor Support
●
Know How
●
Motivation
●
...
Retrofitting monoliths for the future6 10.02.16
Compared with the Software Crisis
●
Development time exceeds initial expectations
●
Poor software quality
●
Project cost exceeds estimated budget
●
Hard-to-maintain codebase
●
A lack of communication with customers
→ Structure the Software Development Process
●
Planning
●
Implementation, Testing and Documentation
●
Deploying, Maintenance
???
Retrofitting monoliths for the future7 10.02.16
Motivation:
Why Monoliths exist...
Retrofitting monoliths for the future8 10.02.16
Why monoliths exist then?
●
Traditional software design
●
Single threaded
●
Synchronous
●
Relying on the „happy-path“
●
Organizational Issues
●
Convey's Law
●
Budgeting Policies
●
Short Time Thinking
●
Skills and Culture
●
Missing or unmatching Objectives and Responsibilities
Retrofitting monoliths for the future9 10.02.16
Why monoliths exist then?
Misunderstandings
●
Software is done once and never touched again
●
Structuring the software process increases software quality
●
Centralization increases efficiency
Bad Practices
●
Do things later (tests, APIs, docs, design, architecture)
●
Inefficient infrastructure
●
Not-invented-by-me syndrom
●
Ivory Towered Guidelines, Gardening
Retrofitting monoliths for the future10 10.02.16
Microservices to our rescue!
Retrofitting monoliths for the future11 10.02.16
Microservices come to our rescue!
The single concern principle matches better with our brains capabilities
Organizing around business capabilities clarifies reponsibilities
Services provide much better isolation than modules
More fine grained options for scaling and failover
Product Orientation follows a long term perspective
Simplicity enables automation
Microservices must be designed for failure!
Microservices enable evolutionary design
Microservices support technological progress
Wow!
Retrofitting monoliths for the future12 10.02.16
Microservices to our rescue!
But...
Retrofitting monoliths for the future13 10.02.16
Microservices are the way to go, but...
It is a long way to go...

Organizing around business capabilities
is not a common approach

They require automation in Ops

They require modern know-how in Dev

Resilient Design is not an easy task

Runtime behaviour, scaling and failover are
not easily predictable

Governance has to be established
→ Microservices consciously
break with many known
practices!
→ Are you microservice-ready?
→ How to get there?
Retrofitting monoliths for the future14 10.02.16
How to get there?
Retrofitting monoliths for the future15 10.02.16
How to go the microservice path?
Start with the preconditions:
●
Fast provisioning of infrastructure (IaaS)
●
Fast provisioning of runtime platforms (PaaS)
●
Orchestration services (e.g. Kubernetes)
●
Monitoring
●
Automated tool-chain
→ Start with a new greenfield organization
→ Only couple with existing providers, if they support the required SLA
→ Start small to gain experience (not yet with microsevices!)
Retrofitting monoliths for the future16 10.02.16
How to go the microservice path?
Add deploying more applications:
●
Add dynamic service discovery and location
●
Think on microservice and API management
●
Think on cloud capable configuration mechanisms
Add further usage scenarios:
●
Integration flows (perfect match, forget ESBs ;-) )
●
Authentication and Authorization services
●
Distributed Message Streams, Log Collectors
●
Error and Dead Letter Queue Handling
●
...
Retrofitting monoliths for the future17 10.02.16
How to go the microservice path?
And not to forget :
●
Add systematic quality measurements to your tool chain
●
Evangelize microservices as an architectural pattern
●
Help people getting better in modularization
●
Manage your people's skills!
And finally :
●
Look at your monoliths
Retrofitting monoliths for the future18 10.02.16
How to got microservice path?
...expect you will fail !
Retrofitting monoliths for the future19 10.02.16
Deep Dive:
Coupling
Retrofitting monoliths for the future20 10.02.16
Coupling: Database Integration
Database Integration
●
Database = large shared API
●
Database design impacts the whole system
●
Brittle
●
Tied to a technology, or even vendor
●
Cohesion (especially with stored procedures)
Retrofitting monoliths for the future21 10.02.16
Coupling: UI Integration
UI Integration
●
Shared API on UI level
●
Brittle
●
Tied to a technology, or even vendor
●
Multiple, sometimes incompatible
frameworks
Retrofitting monoliths for the future22 10.02.16
Coupling: Service Integration
Service Integration
●
Shared API on Business Tier level
●
Brittle
●
Tied to a technology, or even vendor
(e.g. RPCs with EJB/RMI)
●
Unfortunately commonly used in monolithic
systems
Retrofitting monoliths for the future23 10.02.16
Coupling by Communication Design
Synchonous Communication?
●
Long running tasks?
●
Failure Handling
●
Responsivness (Timeouts, non determinism)
●
Request/Response Pattern is also possible with asynch communication
Retrofitting monoliths for the future24 10.02.16
Coupling by Communication Design
Asynchronous Communication
●
Event-Based = inversed asynch („IoC“)
●
Message Brokers or HTTP events (ATOM)
●
Supervision
●
Long running processes?
●
Failures? How to handle bad messages breaking your system?
●
Correlation and Monitoring
Retrofitting monoliths for the future25 10.02.16
Supervision Stategies
Orchestration
●
Central brain to guide and drive
Choreography
●
Inform Component to do work and
let it do its stuff
Boss
EvtsService
Retrofitting monoliths for the future26 10.02.16
Coupling by Data Formats
XML
●
Well defined
●
Heavy
●
Brittle
●
Secure
●
Standardized
●
Inherently inflexible
JSON
●
Easy
●
Lean
●
No link concept, but HAL*
●
No automatic client generation
●
Lean and flexible
* Hypertext app language
Retrofitting monoliths for the future27 10.02.16
Other Coupling Areas
●
Tool Chain and automation infrastructure
●
Shared libraries:
●
Hide from clients!
●
Especially dangerous:
●
Communication frameworks
●
Frameworks for bridging a missing model layer
●
Third Party Products
●
APIs, Lifecycle and Product Quality are out of your control!
●
APIs are normally very badly designed
●
Separate Data Model
Retrofitting monoliths for the future28 10.02.16
How to deal with it?
Breaking things up...
Retrofitting monoliths for the future29 10.02.16
Our Objectives
1. Avoid breaking changes
2. Design APIs technology agnostic and remotable
3. Make services easy for our customers
4. Hide implementation details
Retrofitting monoliths for the future30 10.02.16
Typical Monolithic Architecture
●
Is a monolithic systems a typical combination
of all coupling variants we have identified ???
→ No, it is even worse...!
→ You don't know what it is! It has black areas!
→ You start in blind flight mode!
●
So where to start?
Do small steps and prepare for failure!
Retrofitting monoliths for the future31 10.02.16
Breaking up the Monolith
Where to start?
1.Disentangle the DB (mostly not an
option at the beginning)
2.Disentangle the UI (difficult)
3.Disentangle the Middle Tier
1. Lots of help tool support (IDEs,
compiler build tools, tests)
2. Tests and quality metrics can be
automatically evaluated
3. Fast and automatic feedback
Retrofitting monoliths for the future32 10.02.16
Breaking up the Monolith (2)
How to add bulkheads in a controlled way
●
Analyze your Domains (DDD)
●
Identify technical components
●
Analyse Dependencies
●
Identify Candidates for Isolation
●
Define Component Bounderies and APIs
●
Hide implementation code
●
Discuss impact and issues raised
●
Use static code analysis to enforce
●
Stabilize
●
Do not break up your system (yet)
●
Repeat this process!
Retrofitting monoliths for the future33 10.02.16
Breaking up the Monolith (3)
And the black components left ?
●
Throw away
●
Reimplement
●
Keep them!
●
But ensure
clear and minimal APIs!
●
Deprecate them
!
Retrofitting monoliths for the future34 10.02.16
Breaking up the Monolith (4)
Decouple the database...
●
Change Security Credentials
and wait for shouts!
●
Discuss DB transaction design
●
Discuss failure handling
●
Separate DBs
→ also here: start small and expect
failure!
!
Retrofitting monoliths for the future35 10.02.16
Breaking up the Monolith (5)
Decouple the UI...
●
Apply Backend for the Frontend
Pattern
●
Separate Apps
!
Retrofitting monoliths for the future36 10.02.16
Breaking up the Monolith (6)
And finally you can try to separate
things...
→ APIs are crucial that this works!
!
Retrofitting monoliths for the future37 10.02.16
Aspects not discussed
●
Use tool chain to enforce isolation
●
Version Management and Coexistence
●
Parallel Implementation of Features
●
Project Organisation & Governance Aspects
●
How to deal with Business Continuity (especially on the beginning)
●
...
Retrofitting monoliths for the future38 10.02.16
API Design
Retrofitting monoliths for the future39 10.02.16
What makes an API a good API ?
●
Self-explaining: You don't have to read the documentation.
●
Useful - it addresses a need that is not already met (or improves on existing
ones)
●
Good default behavior - where possible allow extensibility and tweaking
●
Excellent documentation
●
Sample uses and working sample applications (very important)
●
Keep functionality sets distinct and isolated with few if any dependencies.
●
Keep it small or segment it so that it is not one huge polluted space.
Retrofitting monoliths for the future40 10.02.16
But there is more
Good APIs are...
●
Minimalistic, technology agnostic with minimal or no dependencies
●
Strictly interface based (services)
●
Parameters and return types are immutable value types or built-in types
●
All parameters are serializable or designed for remoting
●
Complete, for completeness an accessor singleton maybe useful, but including a
delegation SPI
●
Thread-safe
Retrofitting monoliths for the future41 10.02.16
Principles - General Principles
●
API Should Do One Thing and Do it Well
●
API Should Be As Small As Possible But No Smaller
●
Implementation Should Not Impact API
●
Minimize Accessibility of Everything
●
Names Matter–API is a Little Language
●
Documentation Matters, Document Religiously
●
Consider Performance Consequences of API Design Decisions
●
Effects of API Design Decisions on Performance are Real and Permanent
●
API Must Coexist Peacefully with Platform
Retrofitting monoliths for the future42 10.02.16
Method Design Principles
●
Don't Make the Client Do Anything the Module Could Do
●
Don't Violate the Principle of Least Astonishment
●
Fail Fast - Report Errors as Soon as Possible After They Occur
●
Provide Programmatic Access to All Data Available in String Form
●
Overload With Care
●
Use Appropriate Parameter and Return Types
●
Use Consistent Parameter Ordering Across Methods
●
Avoid Long Parameter Lists
●
Avoid Return Values that Demand Exceptional Processing
Retrofitting monoliths for the future43 10.02.16
Class Design Principles
●
Minimize Mutability
●
Subclass Only Where it Makes Sense
●
Design and Document for Inheritance or Else Prohibit it
Retrofitting monoliths for the future44 10.02.16
Package Design Principles
●
Define a package for each functional module, e.g. com.mycomp.app.auth
●
Move implementation details into com.mycomp.app.auth.internal
●
Move spi interfaces into com.mycomp.app.auth.spi
●
DON'T SEPARATE ARTIFACTS BASED on TYPE, e.g.
●
com.mycomp.app.auth.beans
●
com.mycomp.app.auth.controller
●
com.mycomp.app.auth.model
→ Typically this violates cohesion semantics
→ Use corresponding class names instead, e.g. AuthController, 
  AuthModel
Retrofitting monoliths for the future45 10.02.16
And even more...
We will look now at examples for the following:
1. Establish strong terms (what is a Helper, Utility, …??? )
2. Apply symmetry to term combinations
3. Add convenience through overloading
4. Consistent argument ordering
5. Establish return value types
6. Be careful with exceptions
7. Follow the KISS principle
8. Think on type safety
9. Avoid over-engineering
10.Hide internal at all price
11.Only pass Data or functional types
12.Make APIs Remote Capable
Retrofitting monoliths for the future46 10.02.16
Rule #1: Establish strong terms
●
Use same names for similar functionality
●
Example JDBC Statement, execution of a statement, closing:
execute(String)
executeBatch()
executeQuery(String)
executeUpdate(String)
Connection.close()
Statement.close()
ResultSet.close()
●
close() even ended up in Closeable, AutoCloseable
Retrofitting monoliths for the future47 10.02.16
Rule #1: Establish strong terms - Violations
●
Example of a rule violation in the JDK: java.util.Observable
●
Normally collection like types declare:
size();
remove();
   removeAll();
●
But Observable declares:
countObservers();
deleteObserver(Observer);
deleteObservers();
Retrofitting monoliths for the future48 10.02.16
Rule #1: Establish strong terms - Violations
●
Example of rule violation: the Spring framework. Enjoy:
AbstractBeanFactoryBasedTargetSourceCreator
AbstractInterceptorDrivenBeanDefinitionDecorator
AbstractRefreshablePortletApplicationContext
AspectJAdviceParameterNameDiscoverer
BeanFactoryTransactionAttributeSourceAdvisor
ClassPathScanningCandidateComponentProvider
J2eeBasedPreAuthenticatedWebAuthenticationDetailsSource
→ Creator vs. Factory, a Source vs. Provider, vs Advisor vs Discoverer ???
→ Is an Advisor related to an AspectJAdvice?
→ Is it a ScanningCandidate or a CandidateComponent?
→ TargetSource vs. SourceTarget, or even a SourceSource or a
SourceSourceTargetProviderSource?
Retrofitting monoliths for the future49 10.02.16
Rule #2: Apply symmetry to term combinations
●
Example:
add(E)
  addAll(Collection<? extends E>)
remove(Object)
removeAll(Collection<?>)
contains(Object)
containsAll(Collection<?>)
●
Violation: java.util.Map
●
keySet() → containsKey(Object)
●
values() → containsValue(Object)
●
EntrySet() → missing containsEntry(K, V)
Retrofitting monoliths for the future50 10.02.16
Rule #3: Add convenience through overloading
●
Example:
toArray(), which is a convenient overload of…
toArray(T[])
●
Violation: java.util.TreeSet
●
TreeSet(Collection<? extends E>)
●
TreeSet(SortedSet<E>) → adds some convenience to the first in that it
extracts a well-known Comparator from the argument SortedSet to
preserve ordering, which results in different behavior:
SortedSet<Object> original = // [...]
// Preserves ordering
new TreeSet<Object>(original);
// Resets ordering
new TreeSet<Object>((Collection<Object>) original);
Retrofitting monoliths for the future51 10.02.16
Rule #4: Consistent argument ordering
●
Example java.util.Arrays (array is always first):
copyOf(T[], int), which is an incompatible overload of…
copyOf(boolean[], int)
copyOf(int[], int)
binarySearch(Object[], Object)
copyOfRange(T[], int, int)
fill(Object[], Object)
sort(T[], Comparator<? super T>)
●
Violation: java.util.Arrays by „subtly” putting optional arguments in
between other arguments, when overloading methods:
fill(Object[], Object)
fill(Object[], int, int, Object)
Retrofitting monoliths for the future52 10.02.16
Rule #5: Establish return value types
●
Methods returning a single object should return null when no object was found
●
Methods returning several objects should return an empty List, Set, Map, 
array, etc. when no object was found (never null)
●
Methods should only throw exceptions in case of an … well, an exception
●
Violation: java.util.File.list():
Javadocs: An array of strings naming the files and directories in the directory
denoted by this abstract pathname. The array will be empty if the directory is
empty. Returns null if this abstract pathname does not denote a directory, or if
an I/O error occurs.
Retrofitting monoliths for the future53 10.02.16
Rule #6: Be careful with exceptions
●
Example: java.sql.ResultSet extends java.sql.Wrapper:
public interface Wrapper {
   <T> T unwrap(java.lang.Class<T> iface)
       throws java.sql.SQLException;
   boolean isWrapperFor(java.lang.Class<?> iface)
       throws java.sql.SQLException;
}
 → Exceptions are likely to leak into client code...
→ Use RuntimeException if possible,
Retrofitting monoliths for the future54 10.02.16
Rule #6: Be careful with exceptions
●
Be careful with exceptions, client code:
public void myMethod(){
  ResultSet rs = …;
  if(rs.isWrapperFor(X.class){
    …;
  }
}
throws Exception{
How to handle the exception here?
→ The exception gets an integral part of your API as well!
Retrofitting monoliths for the future55 10.02.16
Rule #7: Follow the KISS principle
Multiple concerns: java.util.Preferences:
public abstract class Preferences {
    private static final PreferencesFactory factory = factory();
    private static PreferencesFactory factory() {...}
    private static PreferencesFactory factory1() {...}
    public static final int MAX_KEY_LENGTH = 80;
    public static final int MAX_VALUE_LENGTH = 8*1024;
    public static final int MAX_NAME_LENGTH = 80;
    
    public static Preferences userNodeForPackage(Class<?> c) {...}
    public static Preferences systemNodeForPackage(Class<?> c) {­­­}
    private static String nodeName(Class<?> c);
    private static Permission prefsPerm = new RuntimePermission("preferences");
    public static Preferences userRoot();
    public static Preferences systemRoot();
    
    protected Preferences() {}
    public abstract void put(String key, String value);
    public abstract String get(String key, String def);
    public abstract void remove(String key);
    [,,,]
→ Management of factories and user
and system tree
→ Implementation details
→ Mapping artifacts to nodes
→ Singleton access to trees
→ Node base class (not an interface!)
→ Mutability is built in already ;(
Retrofitting monoliths for the future56 10.02.16
Rule #7: Follow the KISS principle
Multiple concerns: java.util.Preferences:
    […]
    protected Preferences() {}
    public abstract void put(String key, String value);
    public abstract String get(String key, String def);
    public abstract void remove(String key);
    public abstract void clear() throws BackingStoreException;
    public abstract void putInt(String key, int value);
    public abstract int getInt(String key, int def);
    [...]
    public abstract void putByteArray(String key, byte[] value);
    public abstract byte[] getByteArray(String key, byte[] def);
    public abstract String[] keys() throws BackingStoreException;
    public abstract String[] childrenNames() 
       throws BackingStoreException;
    public abstract Preferences parent();
    public abstract Preferences node(String pathName);
    public abstract boolean nodeExists(String pathName)
        throws BackingStoreException;
    public abstract void removeNode() throws BackingStoreException;
    public abstract String name();
    public abstract String absolutePath();
    public abstract boolean isUserNode();
    […]
    
→ Multi type value support
→ Tree navigation
→ Path/Node translation
→ Tree manipulation
→ Import/Export
→ Utility functions
Retrofitting monoliths for the future57 10.02.16
Rule #7: Follow the KISS principle
Multiple concerns: java.util.Preferences:
    […]
    public abstract void flush() throws BackingStoreException;
    public abstract void sync() throws BackingStoreException;
    public abstract void addPreferenceChangeListener(
        PreferenceChangeListener pcl);
    public abstract void removePreferenceChangeListener(
        PreferenceChangeListener pcl);
    public abstract void addNodeChangeListener(NodeChangeListener ncl);
    public abstract void removeNodeChangeListener(NodeChangeListener ncl);
    public abstract void exportNode(OutputStream os)
        throws IOException, BackingStoreException;
    public abstract void exportSubtree(OutputStream os)
        throws IOException, BackingStoreException;
    
    public static void importPreferences(InputStream is)
        throws IOException, InvalidPreferencesFormatException{}
}
→ Tree manipulation
→ Observer pattern
→ Import/Export
Retrofitting monoliths for the future58 10.02.16
Rule #8: Think on type safety
private String date;
public void setDate(String date);
public String getDate(String date);
● Reason for this design:
custom formats/host APIs
● Flaws:
→ Unclear format
→ No validation
→ Missing datatype
● Alternatives:
● Use JDK time API or JodaTime
Retrofitting monoliths for the future59 10.02.16
Rule #9: Avoid over-engineering
public class UID{
  private String uid;
  public UID(String uid){
    this.uid = uid;
  }
  public String getUid(){
    return uid;
  }
  public void setUid(String uid){
    this.uid = uid;
  }
}
● Reason for this artifact: type safety
● Flaws:
→ Not thread safe
→ No validation
→ No documentation
→ Adds unnecessary complexity
● Alternatives:
● → URIs, e.g.
new URI(“user:a123456“);
Retrofitting monoliths for the future60 10.02.16
Rule #10: Hide internals at all price
public InternalDataSetImpl getDataset(
  String setId, String location,
  String userId, String databaseName,
  String... rules);
public void performAction();
public String manage(Object... args);
● Flaws:
→ Exposes internal data
→ Requires internal data as input
→ Parameter types are error prone
→ Meaningless method name
→ Unconstraint parameters and return
types
Retrofitting monoliths for the future61 10.02.16
Rule #11: Only pass data or functional types
public interface MyFancyService{
  
  public XY evaluateXY(
    Param1 param, 
    EvaluationService service);
  …
}
● Flaws:
→ Requires passing a service
→ not remote capable
● Improvements:
→ Remove service argument
→ It is an implementation detail
● Note:
→ OK for simple functional interfaces
→ Be aware this is broken with
remoting!
Retrofitting monoliths for the future62 10.02.16
Rule #12: Make APIs Remote Capable
● JSON enabled Datatypes
● Strings
● Numbers
● Boolean
● Arrays
● Maps (JSON Object)
→ So everything must be mappable
to this few things!
Retrofitting monoliths for the future63 10.02.16
API Design – Summary
●
API Design is the key discipline of software engineering
●
Start small!
●
Be very causcious to add functionality
●
is it the same concern
●
can't it be done with existing functionality
●
If the API feels too complicated, it definitively IS!
●
Be aware that you have to rework it at least 3 times to get it right
●
Involve colluegues that have experience building public APIs
●
Eat your own dog food!
Retrofitting monoliths for the future64 10.02.16
Summary
Retrofitting monoliths for the future65 10.02.16
Summary
●
Microservices, Containers and Resilient Design are the Future.
●
Monoliths are inherently broken for building highly scalable, resilient systems.
●
Decoupling affects everything: your infrastructure, your organization, your data,
your skills.
●
It's a long and difficult path.
●
You will probably fail.
●
But IMO you dont have a choice *
●
Act now!
* compare the impact on taxi companies when Uber.com entered the market
Retrofitting monoliths for the future66 10.02.16
Referenzen
●
Sam Newman: Building Microservices. O'Reilly, 2015
●
Martin Fowler: Microservices. http://martinfowler.com/articles/microservices.html
●
Resilient Software Design:
https://jaxenter.de/unkaputtbar-einfuehrung-resilient-software-design-15119
●
API Design in Java: https://dzone.com/articles/how-design-good-regular-api
Retrofitting monoliths for the future67 10.02.16
Monolithen für die Zukunft trimmen
Anatole Tresch
Principal Consultant
Tel. +41 58 459 53 93
anatole.tresch@trivadis.com

Weitere ähnliche Inhalte

Ähnlich wie Wie Monolithen für die Zukuft trimmen

Why kernelspace sucks?
Why kernelspace sucks?Why kernelspace sucks?
Why kernelspace sucks?
OpenFest team
 
Effective cplusplus
Effective cplusplusEffective cplusplus
Effective cplusplus
Mark Veltzer
 

Ähnlich wie Wie Monolithen für die Zukuft trimmen (20)

Breaking down a monolith
Breaking down a monolithBreaking down a monolith
Breaking down a monolith
 
Viktor Turskyi "Effective NodeJS Application Development"
Viktor Turskyi "Effective NodeJS Application Development"Viktor Turskyi "Effective NodeJS Application Development"
Viktor Turskyi "Effective NodeJS Application Development"
 
Monolith to microservices journey
Monolith to microservices journeyMonolith to microservices journey
Monolith to microservices journey
 
The working architecture of NodeJS applications, Виктор Турский
The working architecture of NodeJS applications, Виктор ТурскийThe working architecture of NodeJS applications, Виктор Турский
The working architecture of NodeJS applications, Виктор Турский
 
The working architecture of node js applications open tech week javascript ...
The working architecture of node js applications   open tech week javascript ...The working architecture of node js applications   open tech week javascript ...
The working architecture of node js applications open tech week javascript ...
 
Montreal Kubernetes Meetup: Developer-first workflows (for microservices) on ...
Montreal Kubernetes Meetup: Developer-first workflows (for microservices) on ...Montreal Kubernetes Meetup: Developer-first workflows (for microservices) on ...
Montreal Kubernetes Meetup: Developer-first workflows (for microservices) on ...
 
'Effective node.js development' by Viktor Turskyi at OdessaJS'2020
'Effective node.js development' by Viktor Turskyi at OdessaJS'2020'Effective node.js development' by Viktor Turskyi at OdessaJS'2020
'Effective node.js development' by Viktor Turskyi at OdessaJS'2020
 
FEVR - Micro Frontend
FEVR - Micro FrontendFEVR - Micro Frontend
FEVR - Micro Frontend
 
Micro service pitfalls voxxed days istanbul 2015
Micro service pitfalls voxxed days istanbul 2015Micro service pitfalls voxxed days istanbul 2015
Micro service pitfalls voxxed days istanbul 2015
 
Moving from Monolith to Microservices
Moving from Monolith to MicroservicesMoving from Monolith to Microservices
Moving from Monolith to Microservices
 
Containerizing couchbase with microservice architecture on mesosphere.pptx
Containerizing couchbase with microservice architecture on mesosphere.pptxContainerizing couchbase with microservice architecture on mesosphere.pptx
Containerizing couchbase with microservice architecture on mesosphere.pptx
 
AWS Community Day: From Monolith to Microservices - What Could Go Wrong?
AWS Community Day: From Monolith to Microservices - What Could Go Wrong?AWS Community Day: From Monolith to Microservices - What Could Go Wrong?
AWS Community Day: From Monolith to Microservices - What Could Go Wrong?
 
Why kernelspace sucks?
Why kernelspace sucks?Why kernelspace sucks?
Why kernelspace sucks?
 
Not my problem - Delegating responsibility to infrastructure
Not my problem - Delegating responsibility to infrastructureNot my problem - Delegating responsibility to infrastructure
Not my problem - Delegating responsibility to infrastructure
 
Effective cplusplus
Effective cplusplusEffective cplusplus
Effective cplusplus
 
Pareto will tell you to stop using your ORM - Mateo Collina
Pareto will tell you to stop using your ORM - Mateo CollinaPareto will tell you to stop using your ORM - Mateo Collina
Pareto will tell you to stop using your ORM - Mateo Collina
 
Data Science in Production: Technologies That Drive Adoption of Data Science ...
Data Science in Production: Technologies That Drive Adoption of Data Science ...Data Science in Production: Technologies That Drive Adoption of Data Science ...
Data Science in Production: Technologies That Drive Adoption of Data Science ...
 
JAX DevOps 2019: "Creating an Effective Developer Experience for Cloud-native...
JAX DevOps 2019: "Creating an Effective Developer Experience for Cloud-native...JAX DevOps 2019: "Creating an Effective Developer Experience for Cloud-native...
JAX DevOps 2019: "Creating an Effective Developer Experience for Cloud-native...
 
Migrating from oracle soa suite to microservices on kubernetes
Migrating from oracle soa suite to microservices on kubernetesMigrating from oracle soa suite to microservices on kubernetes
Migrating from oracle soa suite to microservices on kubernetes
 
Performance monitoring and call tracing in microservice environments
Performance monitoring and call tracing in microservice environmentsPerformance monitoring and call tracing in microservice environments
Performance monitoring and call tracing in microservice environments
 

Mehr von Anatole Tresch

Mehr von Anatole Tresch (17)

Jsr382: Konfiguration in Java
Jsr382: Konfiguration in JavaJsr382: Konfiguration in Java
Jsr382: Konfiguration in Java
 
Wie man Applikationen nicht bauen sollte...
Wie man Applikationen nicht bauen sollte...Wie man Applikationen nicht bauen sollte...
Wie man Applikationen nicht bauen sollte...
 
The Gib Five - Modern IT Architecture
The Gib Five - Modern IT ArchitectureThe Gib Five - Modern IT Architecture
The Gib Five - Modern IT Architecture
 
The Big Five - IT Architektur Heute
The Big Five - IT Architektur HeuteThe Big Five - IT Architektur Heute
The Big Five - IT Architektur Heute
 
Microservices in Java
Microservices in JavaMicroservices in Java
Microservices in Java
 
Disruption is Change is Future
Disruption is Change is FutureDisruption is Change is Future
Disruption is Change is Future
 
Configuration with Microprofile and Apache Tamaya
Configuration with Microprofile and Apache TamayaConfiguration with Microprofile and Apache Tamaya
Configuration with Microprofile and Apache Tamaya
 
Going Resilient...
Going Resilient...Going Resilient...
Going Resilient...
 
Configure once, run everywhere 2016
Configure once, run everywhere 2016Configure once, run everywhere 2016
Configure once, run everywhere 2016
 
Configuration with Apache Tamaya
Configuration with Apache TamayaConfiguration with Apache Tamaya
Configuration with Apache Tamaya
 
Configure Your Projects with Apache Tamaya
Configure Your Projects with Apache TamayaConfigure Your Projects with Apache Tamaya
Configure Your Projects with Apache Tamaya
 
JSR 354 Hackday - What you can do...
JSR 354 Hackday - What you can do...JSR 354 Hackday - What you can do...
JSR 354 Hackday - What you can do...
 
Legacy Renewal of Central Framework in the Enterprise
Legacy Renewal of Central Framework in the EnterpriseLegacy Renewal of Central Framework in the Enterprise
Legacy Renewal of Central Framework in the Enterprise
 
Go for the Money: eine Einführung in JSR 354 - Java aktuell 2014 - Anatole Tr...
Go for the Money: eine Einführung in JSR 354 - Java aktuell 2014 - Anatole Tr...Go for the Money: eine Einführung in JSR 354 - Java aktuell 2014 - Anatole Tr...
Go for the Money: eine Einführung in JSR 354 - Java aktuell 2014 - Anatole Tr...
 
A first Draft to Java Configuration
A first Draft to Java ConfigurationA first Draft to Java Configuration
A first Draft to Java Configuration
 
JSR 354 LJC-Hackday
JSR 354 LJC-HackdayJSR 354 LJC-Hackday
JSR 354 LJC-Hackday
 
Adopt JSR 354
Adopt JSR 354Adopt JSR 354
Adopt JSR 354
 

Kürzlich hochgeladen

+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
Health
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
VictorSzoltysek
 

Kürzlich hochgeladen (20)

call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
%in Stilfontein+277-882-255-28 abortion pills for sale in Stilfontein
 
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time ApplicationsUnveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
Unveiling the Tech Salsa of LAMs with Janus in Real-Time Applications
 
8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students8257 interfacing 2 in microprocessor for btech students
8257 interfacing 2 in microprocessor for btech students
 
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456LEVEL 5   - SESSION 1 2023 (1).pptx - PDF 123456
LEVEL 5 - SESSION 1 2023 (1).pptx - PDF 123456
 
Pharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodologyPharm-D Biostatistics and Research methodology
Pharm-D Biostatistics and Research methodology
 
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
+971565801893>>SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHAB...
 
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
W01_panagenda_Navigating-the-Future-with-The-Hitchhikers-Guide-to-Notes-and-D...
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
Crypto Cloud Review - How To Earn Up To $500 Per DAY Of Bitcoin 100% On AutoP...
 
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM TechniquesAI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
AI Mastery 201: Elevating Your Workflow with Advanced LLM Techniques
 
Microsoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdfMicrosoft AI Transformation Partner Playbook.pdf
Microsoft AI Transformation Partner Playbook.pdf
 
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa%in tembisa+277-882-255-28 abortion pills for sale in tembisa
%in tembisa+277-882-255-28 abortion pills for sale in tembisa
 
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptxBUS PASS MANGEMENT SYSTEM USING PHP.pptx
BUS PASS MANGEMENT SYSTEM USING PHP.pptx
 
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdfThe Top App Development Trends Shaping the Industry in 2024-25 .pdf
The Top App Development Trends Shaping the Industry in 2024-25 .pdf
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
%in Bahrain+277-882-255-28 abortion pills for sale in Bahrain
 

Wie Monolithen für die Zukuft trimmen

  • 1. BASEL BERN BRUGG DÜSSELDORF FRANKFURT A.M. FREIBURG I.BR. GENF HAMBURG KOPENHAGEN LAUSANNE MÜNCHEN STUTTGART WIEN ZÜRICH Monolithen fit für die Zukunft trimmen Warum Monolithen entstehen und wie Microservices helfen können, die Biester zu bändigen Anatole Tresch, Principal Consultant
  • 2. Retrofitting monoliths for the future2 25.11.15 BIO Anatole Tresch ● Principal Consultant, Trivadis AG (Switzerland) ● Star Spec Lead JSR 354 ● Technical Architect, Lead Engineer ● PPMC Member Apache Tamaya ● Twitter/Google+: @atsticks ● atsticks@java.net ● anatole.tresch@trivadis.com ●
  • 3. Retrofitting monoliths for the future3 25.11.15 Agenda ● Motivation ● Microservices to our rescue! ● How to get there? ● Deep Dive: ● Coupling ● Breaking things up ● API Design ● Summary
  • 4. Retrofitting monoliths for the future4 10.02.16 Motivation: Why are monoliths a problem?
  • 5. Retrofitting monoliths for the future5 10.02.16 Why are monoliths a problem? ● Maintenance Costs ● Time to Market ● Performance ● Stability and Robustness (forget Resilience!) ● Flexibility (e.g. for Integration) ● Vendor Support ● Know How ● Motivation ● ...
  • 6. Retrofitting monoliths for the future6 10.02.16 Compared with the Software Crisis ● Development time exceeds initial expectations ● Poor software quality ● Project cost exceeds estimated budget ● Hard-to-maintain codebase ● A lack of communication with customers → Structure the Software Development Process ● Planning ● Implementation, Testing and Documentation ● Deploying, Maintenance ???
  • 7. Retrofitting monoliths for the future7 10.02.16 Motivation: Why Monoliths exist...
  • 8. Retrofitting monoliths for the future8 10.02.16 Why monoliths exist then? ● Traditional software design ● Single threaded ● Synchronous ● Relying on the „happy-path“ ● Organizational Issues ● Convey's Law ● Budgeting Policies ● Short Time Thinking ● Skills and Culture ● Missing or unmatching Objectives and Responsibilities
  • 9. Retrofitting monoliths for the future9 10.02.16 Why monoliths exist then? Misunderstandings ● Software is done once and never touched again ● Structuring the software process increases software quality ● Centralization increases efficiency Bad Practices ● Do things later (tests, APIs, docs, design, architecture) ● Inefficient infrastructure ● Not-invented-by-me syndrom ● Ivory Towered Guidelines, Gardening
  • 10. Retrofitting monoliths for the future10 10.02.16 Microservices to our rescue!
  • 11. Retrofitting monoliths for the future11 10.02.16 Microservices come to our rescue! The single concern principle matches better with our brains capabilities Organizing around business capabilities clarifies reponsibilities Services provide much better isolation than modules More fine grained options for scaling and failover Product Orientation follows a long term perspective Simplicity enables automation Microservices must be designed for failure! Microservices enable evolutionary design Microservices support technological progress Wow!
  • 12. Retrofitting monoliths for the future12 10.02.16 Microservices to our rescue! But...
  • 13. Retrofitting monoliths for the future13 10.02.16 Microservices are the way to go, but... It is a long way to go...  Organizing around business capabilities is not a common approach  They require automation in Ops  They require modern know-how in Dev  Resilient Design is not an easy task  Runtime behaviour, scaling and failover are not easily predictable  Governance has to be established → Microservices consciously break with many known practices! → Are you microservice-ready? → How to get there?
  • 14. Retrofitting monoliths for the future14 10.02.16 How to get there?
  • 15. Retrofitting monoliths for the future15 10.02.16 How to go the microservice path? Start with the preconditions: ● Fast provisioning of infrastructure (IaaS) ● Fast provisioning of runtime platforms (PaaS) ● Orchestration services (e.g. Kubernetes) ● Monitoring ● Automated tool-chain → Start with a new greenfield organization → Only couple with existing providers, if they support the required SLA → Start small to gain experience (not yet with microsevices!)
  • 16. Retrofitting monoliths for the future16 10.02.16 How to go the microservice path? Add deploying more applications: ● Add dynamic service discovery and location ● Think on microservice and API management ● Think on cloud capable configuration mechanisms Add further usage scenarios: ● Integration flows (perfect match, forget ESBs ;-) ) ● Authentication and Authorization services ● Distributed Message Streams, Log Collectors ● Error and Dead Letter Queue Handling ● ...
  • 17. Retrofitting monoliths for the future17 10.02.16 How to go the microservice path? And not to forget : ● Add systematic quality measurements to your tool chain ● Evangelize microservices as an architectural pattern ● Help people getting better in modularization ● Manage your people's skills! And finally : ● Look at your monoliths
  • 18. Retrofitting monoliths for the future18 10.02.16 How to got microservice path? ...expect you will fail !
  • 19. Retrofitting monoliths for the future19 10.02.16 Deep Dive: Coupling
  • 20. Retrofitting monoliths for the future20 10.02.16 Coupling: Database Integration Database Integration ● Database = large shared API ● Database design impacts the whole system ● Brittle ● Tied to a technology, or even vendor ● Cohesion (especially with stored procedures)
  • 21. Retrofitting monoliths for the future21 10.02.16 Coupling: UI Integration UI Integration ● Shared API on UI level ● Brittle ● Tied to a technology, or even vendor ● Multiple, sometimes incompatible frameworks
  • 22. Retrofitting monoliths for the future22 10.02.16 Coupling: Service Integration Service Integration ● Shared API on Business Tier level ● Brittle ● Tied to a technology, or even vendor (e.g. RPCs with EJB/RMI) ● Unfortunately commonly used in monolithic systems
  • 23. Retrofitting monoliths for the future23 10.02.16 Coupling by Communication Design Synchonous Communication? ● Long running tasks? ● Failure Handling ● Responsivness (Timeouts, non determinism) ● Request/Response Pattern is also possible with asynch communication
  • 24. Retrofitting monoliths for the future24 10.02.16 Coupling by Communication Design Asynchronous Communication ● Event-Based = inversed asynch („IoC“) ● Message Brokers or HTTP events (ATOM) ● Supervision ● Long running processes? ● Failures? How to handle bad messages breaking your system? ● Correlation and Monitoring
  • 25. Retrofitting monoliths for the future25 10.02.16 Supervision Stategies Orchestration ● Central brain to guide and drive Choreography ● Inform Component to do work and let it do its stuff Boss EvtsService
  • 26. Retrofitting monoliths for the future26 10.02.16 Coupling by Data Formats XML ● Well defined ● Heavy ● Brittle ● Secure ● Standardized ● Inherently inflexible JSON ● Easy ● Lean ● No link concept, but HAL* ● No automatic client generation ● Lean and flexible * Hypertext app language
  • 27. Retrofitting monoliths for the future27 10.02.16 Other Coupling Areas ● Tool Chain and automation infrastructure ● Shared libraries: ● Hide from clients! ● Especially dangerous: ● Communication frameworks ● Frameworks for bridging a missing model layer ● Third Party Products ● APIs, Lifecycle and Product Quality are out of your control! ● APIs are normally very badly designed ● Separate Data Model
  • 28. Retrofitting monoliths for the future28 10.02.16 How to deal with it? Breaking things up...
  • 29. Retrofitting monoliths for the future29 10.02.16 Our Objectives 1. Avoid breaking changes 2. Design APIs technology agnostic and remotable 3. Make services easy for our customers 4. Hide implementation details
  • 30. Retrofitting monoliths for the future30 10.02.16 Typical Monolithic Architecture ● Is a monolithic systems a typical combination of all coupling variants we have identified ??? → No, it is even worse...! → You don't know what it is! It has black areas! → You start in blind flight mode! ● So where to start? Do small steps and prepare for failure!
  • 31. Retrofitting monoliths for the future31 10.02.16 Breaking up the Monolith Where to start? 1.Disentangle the DB (mostly not an option at the beginning) 2.Disentangle the UI (difficult) 3.Disentangle the Middle Tier 1. Lots of help tool support (IDEs, compiler build tools, tests) 2. Tests and quality metrics can be automatically evaluated 3. Fast and automatic feedback
  • 32. Retrofitting monoliths for the future32 10.02.16 Breaking up the Monolith (2) How to add bulkheads in a controlled way ● Analyze your Domains (DDD) ● Identify technical components ● Analyse Dependencies ● Identify Candidates for Isolation ● Define Component Bounderies and APIs ● Hide implementation code ● Discuss impact and issues raised ● Use static code analysis to enforce ● Stabilize ● Do not break up your system (yet) ● Repeat this process!
  • 33. Retrofitting monoliths for the future33 10.02.16 Breaking up the Monolith (3) And the black components left ? ● Throw away ● Reimplement ● Keep them! ● But ensure clear and minimal APIs! ● Deprecate them !
  • 34. Retrofitting monoliths for the future34 10.02.16 Breaking up the Monolith (4) Decouple the database... ● Change Security Credentials and wait for shouts! ● Discuss DB transaction design ● Discuss failure handling ● Separate DBs → also here: start small and expect failure! !
  • 35. Retrofitting monoliths for the future35 10.02.16 Breaking up the Monolith (5) Decouple the UI... ● Apply Backend for the Frontend Pattern ● Separate Apps !
  • 36. Retrofitting monoliths for the future36 10.02.16 Breaking up the Monolith (6) And finally you can try to separate things... → APIs are crucial that this works! !
  • 37. Retrofitting monoliths for the future37 10.02.16 Aspects not discussed ● Use tool chain to enforce isolation ● Version Management and Coexistence ● Parallel Implementation of Features ● Project Organisation & Governance Aspects ● How to deal with Business Continuity (especially on the beginning) ● ...
  • 38. Retrofitting monoliths for the future38 10.02.16 API Design
  • 39. Retrofitting monoliths for the future39 10.02.16 What makes an API a good API ? ● Self-explaining: You don't have to read the documentation. ● Useful - it addresses a need that is not already met (or improves on existing ones) ● Good default behavior - where possible allow extensibility and tweaking ● Excellent documentation ● Sample uses and working sample applications (very important) ● Keep functionality sets distinct and isolated with few if any dependencies. ● Keep it small or segment it so that it is not one huge polluted space.
  • 40. Retrofitting monoliths for the future40 10.02.16 But there is more Good APIs are... ● Minimalistic, technology agnostic with minimal or no dependencies ● Strictly interface based (services) ● Parameters and return types are immutable value types or built-in types ● All parameters are serializable or designed for remoting ● Complete, for completeness an accessor singleton maybe useful, but including a delegation SPI ● Thread-safe
  • 41. Retrofitting monoliths for the future41 10.02.16 Principles - General Principles ● API Should Do One Thing and Do it Well ● API Should Be As Small As Possible But No Smaller ● Implementation Should Not Impact API ● Minimize Accessibility of Everything ● Names Matter–API is a Little Language ● Documentation Matters, Document Religiously ● Consider Performance Consequences of API Design Decisions ● Effects of API Design Decisions on Performance are Real and Permanent ● API Must Coexist Peacefully with Platform
  • 42. Retrofitting monoliths for the future42 10.02.16 Method Design Principles ● Don't Make the Client Do Anything the Module Could Do ● Don't Violate the Principle of Least Astonishment ● Fail Fast - Report Errors as Soon as Possible After They Occur ● Provide Programmatic Access to All Data Available in String Form ● Overload With Care ● Use Appropriate Parameter and Return Types ● Use Consistent Parameter Ordering Across Methods ● Avoid Long Parameter Lists ● Avoid Return Values that Demand Exceptional Processing
  • 43. Retrofitting monoliths for the future43 10.02.16 Class Design Principles ● Minimize Mutability ● Subclass Only Where it Makes Sense ● Design and Document for Inheritance or Else Prohibit it
  • 44. Retrofitting monoliths for the future44 10.02.16 Package Design Principles ● Define a package for each functional module, e.g. com.mycomp.app.auth ● Move implementation details into com.mycomp.app.auth.internal ● Move spi interfaces into com.mycomp.app.auth.spi ● DON'T SEPARATE ARTIFACTS BASED on TYPE, e.g. ● com.mycomp.app.auth.beans ● com.mycomp.app.auth.controller ● com.mycomp.app.auth.model → Typically this violates cohesion semantics → Use corresponding class names instead, e.g. AuthController,    AuthModel
  • 45. Retrofitting monoliths for the future45 10.02.16 And even more... We will look now at examples for the following: 1. Establish strong terms (what is a Helper, Utility, …??? ) 2. Apply symmetry to term combinations 3. Add convenience through overloading 4. Consistent argument ordering 5. Establish return value types 6. Be careful with exceptions 7. Follow the KISS principle 8. Think on type safety 9. Avoid over-engineering 10.Hide internal at all price 11.Only pass Data or functional types 12.Make APIs Remote Capable
  • 46. Retrofitting monoliths for the future46 10.02.16 Rule #1: Establish strong terms ● Use same names for similar functionality ● Example JDBC Statement, execution of a statement, closing: execute(String) executeBatch() executeQuery(String) executeUpdate(String) Connection.close() Statement.close() ResultSet.close() ● close() even ended up in Closeable, AutoCloseable
  • 47. Retrofitting monoliths for the future47 10.02.16 Rule #1: Establish strong terms - Violations ● Example of a rule violation in the JDK: java.util.Observable ● Normally collection like types declare: size(); remove();    removeAll(); ● But Observable declares: countObservers(); deleteObserver(Observer); deleteObservers();
  • 48. Retrofitting monoliths for the future48 10.02.16 Rule #1: Establish strong terms - Violations ● Example of rule violation: the Spring framework. Enjoy: AbstractBeanFactoryBasedTargetSourceCreator AbstractInterceptorDrivenBeanDefinitionDecorator AbstractRefreshablePortletApplicationContext AspectJAdviceParameterNameDiscoverer BeanFactoryTransactionAttributeSourceAdvisor ClassPathScanningCandidateComponentProvider J2eeBasedPreAuthenticatedWebAuthenticationDetailsSource → Creator vs. Factory, a Source vs. Provider, vs Advisor vs Discoverer ??? → Is an Advisor related to an AspectJAdvice? → Is it a ScanningCandidate or a CandidateComponent? → TargetSource vs. SourceTarget, or even a SourceSource or a SourceSourceTargetProviderSource?
  • 49. Retrofitting monoliths for the future49 10.02.16 Rule #2: Apply symmetry to term combinations ● Example: add(E)   addAll(Collection<? extends E>) remove(Object) removeAll(Collection<?>) contains(Object) containsAll(Collection<?>) ● Violation: java.util.Map ● keySet() → containsKey(Object) ● values() → containsValue(Object) ● EntrySet() → missing containsEntry(K, V)
  • 50. Retrofitting monoliths for the future50 10.02.16 Rule #3: Add convenience through overloading ● Example: toArray(), which is a convenient overload of… toArray(T[]) ● Violation: java.util.TreeSet ● TreeSet(Collection<? extends E>) ● TreeSet(SortedSet<E>) → adds some convenience to the first in that it extracts a well-known Comparator from the argument SortedSet to preserve ordering, which results in different behavior: SortedSet<Object> original = // [...] // Preserves ordering new TreeSet<Object>(original); // Resets ordering new TreeSet<Object>((Collection<Object>) original);
  • 51. Retrofitting monoliths for the future51 10.02.16 Rule #4: Consistent argument ordering ● Example java.util.Arrays (array is always first): copyOf(T[], int), which is an incompatible overload of… copyOf(boolean[], int) copyOf(int[], int) binarySearch(Object[], Object) copyOfRange(T[], int, int) fill(Object[], Object) sort(T[], Comparator<? super T>) ● Violation: java.util.Arrays by „subtly” putting optional arguments in between other arguments, when overloading methods: fill(Object[], Object) fill(Object[], int, int, Object)
  • 52. Retrofitting monoliths for the future52 10.02.16 Rule #5: Establish return value types ● Methods returning a single object should return null when no object was found ● Methods returning several objects should return an empty List, Set, Map,  array, etc. when no object was found (never null) ● Methods should only throw exceptions in case of an … well, an exception ● Violation: java.util.File.list(): Javadocs: An array of strings naming the files and directories in the directory denoted by this abstract pathname. The array will be empty if the directory is empty. Returns null if this abstract pathname does not denote a directory, or if an I/O error occurs.
  • 53. Retrofitting monoliths for the future53 10.02.16 Rule #6: Be careful with exceptions ● Example: java.sql.ResultSet extends java.sql.Wrapper: public interface Wrapper {    <T> T unwrap(java.lang.Class<T> iface)        throws java.sql.SQLException;    boolean isWrapperFor(java.lang.Class<?> iface)        throws java.sql.SQLException; }  → Exceptions are likely to leak into client code... → Use RuntimeException if possible,
  • 54. Retrofitting monoliths for the future54 10.02.16 Rule #6: Be careful with exceptions ● Be careful with exceptions, client code: public void myMethod(){   ResultSet rs = …;   if(rs.isWrapperFor(X.class){     …;   } } throws Exception{ How to handle the exception here? → The exception gets an integral part of your API as well!
  • 55. Retrofitting monoliths for the future55 10.02.16 Rule #7: Follow the KISS principle Multiple concerns: java.util.Preferences: public abstract class Preferences {     private static final PreferencesFactory factory = factory();     private static PreferencesFactory factory() {...}     private static PreferencesFactory factory1() {...}     public static final int MAX_KEY_LENGTH = 80;     public static final int MAX_VALUE_LENGTH = 8*1024;     public static final int MAX_NAME_LENGTH = 80;          public static Preferences userNodeForPackage(Class<?> c) {...}     public static Preferences systemNodeForPackage(Class<?> c) {­­­}     private static String nodeName(Class<?> c);     private static Permission prefsPerm = new RuntimePermission("preferences");     public static Preferences userRoot();     public static Preferences systemRoot();          protected Preferences() {}     public abstract void put(String key, String value);     public abstract String get(String key, String def);     public abstract void remove(String key);     [,,,] → Management of factories and user and system tree → Implementation details → Mapping artifacts to nodes → Singleton access to trees → Node base class (not an interface!) → Mutability is built in already ;(
  • 56. Retrofitting monoliths for the future56 10.02.16 Rule #7: Follow the KISS principle Multiple concerns: java.util.Preferences:     […]     protected Preferences() {}     public abstract void put(String key, String value);     public abstract String get(String key, String def);     public abstract void remove(String key);     public abstract void clear() throws BackingStoreException;     public abstract void putInt(String key, int value);     public abstract int getInt(String key, int def);     [...]     public abstract void putByteArray(String key, byte[] value);     public abstract byte[] getByteArray(String key, byte[] def);     public abstract String[] keys() throws BackingStoreException;     public abstract String[] childrenNames()         throws BackingStoreException;     public abstract Preferences parent();     public abstract Preferences node(String pathName);     public abstract boolean nodeExists(String pathName)         throws BackingStoreException;     public abstract void removeNode() throws BackingStoreException;     public abstract String name();     public abstract String absolutePath();     public abstract boolean isUserNode();     […]      → Multi type value support → Tree navigation → Path/Node translation → Tree manipulation → Import/Export → Utility functions
  • 57. Retrofitting monoliths for the future57 10.02.16 Rule #7: Follow the KISS principle Multiple concerns: java.util.Preferences:     […]     public abstract void flush() throws BackingStoreException;     public abstract void sync() throws BackingStoreException;     public abstract void addPreferenceChangeListener(         PreferenceChangeListener pcl);     public abstract void removePreferenceChangeListener(         PreferenceChangeListener pcl);     public abstract void addNodeChangeListener(NodeChangeListener ncl);     public abstract void removeNodeChangeListener(NodeChangeListener ncl);     public abstract void exportNode(OutputStream os)         throws IOException, BackingStoreException;     public abstract void exportSubtree(OutputStream os)         throws IOException, BackingStoreException;          public static void importPreferences(InputStream is)         throws IOException, InvalidPreferencesFormatException{} } → Tree manipulation → Observer pattern → Import/Export
  • 58. Retrofitting monoliths for the future58 10.02.16 Rule #8: Think on type safety private String date; public void setDate(String date); public String getDate(String date); ● Reason for this design: custom formats/host APIs ● Flaws: → Unclear format → No validation → Missing datatype ● Alternatives: ● Use JDK time API or JodaTime
  • 59. Retrofitting monoliths for the future59 10.02.16 Rule #9: Avoid over-engineering public class UID{   private String uid;   public UID(String uid){     this.uid = uid;   }   public String getUid(){     return uid;   }   public void setUid(String uid){     this.uid = uid;   } } ● Reason for this artifact: type safety ● Flaws: → Not thread safe → No validation → No documentation → Adds unnecessary complexity ● Alternatives: ● → URIs, e.g. new URI(“user:a123456“);
  • 60. Retrofitting monoliths for the future60 10.02.16 Rule #10: Hide internals at all price public InternalDataSetImpl getDataset(   String setId, String location,   String userId, String databaseName,   String... rules); public void performAction(); public String manage(Object... args); ● Flaws: → Exposes internal data → Requires internal data as input → Parameter types are error prone → Meaningless method name → Unconstraint parameters and return types
  • 61. Retrofitting monoliths for the future61 10.02.16 Rule #11: Only pass data or functional types public interface MyFancyService{      public XY evaluateXY(     Param1 param,      EvaluationService service);   … } ● Flaws: → Requires passing a service → not remote capable ● Improvements: → Remove service argument → It is an implementation detail ● Note: → OK for simple functional interfaces → Be aware this is broken with remoting!
  • 62. Retrofitting monoliths for the future62 10.02.16 Rule #12: Make APIs Remote Capable ● JSON enabled Datatypes ● Strings ● Numbers ● Boolean ● Arrays ● Maps (JSON Object) → So everything must be mappable to this few things!
  • 63. Retrofitting monoliths for the future63 10.02.16 API Design – Summary ● API Design is the key discipline of software engineering ● Start small! ● Be very causcious to add functionality ● is it the same concern ● can't it be done with existing functionality ● If the API feels too complicated, it definitively IS! ● Be aware that you have to rework it at least 3 times to get it right ● Involve colluegues that have experience building public APIs ● Eat your own dog food!
  • 64. Retrofitting monoliths for the future64 10.02.16 Summary
  • 65. Retrofitting monoliths for the future65 10.02.16 Summary ● Microservices, Containers and Resilient Design are the Future. ● Monoliths are inherently broken for building highly scalable, resilient systems. ● Decoupling affects everything: your infrastructure, your organization, your data, your skills. ● It's a long and difficult path. ● You will probably fail. ● But IMO you dont have a choice * ● Act now! * compare the impact on taxi companies when Uber.com entered the market
  • 66. Retrofitting monoliths for the future66 10.02.16 Referenzen ● Sam Newman: Building Microservices. O'Reilly, 2015 ● Martin Fowler: Microservices. http://martinfowler.com/articles/microservices.html ● Resilient Software Design: https://jaxenter.de/unkaputtbar-einfuehrung-resilient-software-design-15119 ● API Design in Java: https://dzone.com/articles/how-design-good-regular-api
  • 67. Retrofitting monoliths for the future67 10.02.16 Monolithen für die Zukunft trimmen Anatole Tresch Principal Consultant Tel. +41 58 459 53 93 anatole.tresch@trivadis.com