SlideShare a Scribd company logo
Writing Scalable
Software in Java
From multi-core to grid-computing
Me

•   Ruben Badaró
•   Dev Expert at Changingworlds/Amdocs
•   PT.JUG Leader
•   http://www.zonaj.org
What this talk is not
       about
• Sales pitch
• Cloud Computing
• Service Oriented Architectures
• Java EE
• How to write multi-threaded code
Summary

• Define Performance and Scalability
• Vertical Scalability - scaling up
• Horizontal Scalability - scaling out
• Q&A
Performance != Scalability
Performance


 Amount of useful work accomplished by a
computer system compared to the time and
             resources used
Scalability


Capability of a system to increase the amount of
useful work as resources and load are added to
                    the system
Scalability

•   A system that performs fast with 10 users
    might not do so with 1000 - it doesn’t scale
•   Designing for scalability always decreases
    performance
Linear Scalability
Throughput




                          Resources
Reality is sub-linear
Throughput




                     Resources
Amdahl’s Law
Scalability is about
       parallelizing
• Parallel decomposition allows division of
  work
• Parallelizing might mean more work
• There’s almost always a part of serial
  computation
Vertical Scalability
Vertical Scalability
      Somewhat hard
Vertical Scalability
                      Scale Up

•   Bigger, meaner machines
    -   More cores (and more powerful)
    -   More memory
    -   Faster local storage
•   Limited
    -   Technical constraints
    -   Cost - big machines get exponentially
        expensive
Shared State

• Need to use those cores
• Java - shared-state concurrency
 - Mutable state protected with locks
 - Hard to get right
 - Most developers don’t have experience
    writing multithreaded code
This is how they look
              like
public static synchronized SomeObject getInstance() {

    return instance;

}



public SomeObject doConcurrentThingy() {

    synchronized(this) {

        //...

    }

    return ..;

}
Single vs Multi-threaded
 •   Single-threaded

     -   No scheduling cost
     -   No synchronization cost
 •   Multi-threaded
     -   Context Switching (high cost)
     -   Memory Synchronization (memory barriers)
     -   Blocking
Lock Contention
             Little’s Law


The average number of customers in a stable
 system is equal to their average arrival rate
multiplied by their average time in the system
Reducing Contention
•   Reduce lock duration
•   Reduce frequency with which locks are
    requested (stripping)
•   Replace exclusive locks with other mechanisms
    -   Concurrent Collections
    -   ReadWriteLocks
    -   Atomic Variables
    -   Immutable Objects
Concurrent Collections

 • Use lock stripping
 • Includes    putIfAbsent()   and replace()
     methods
 •   ConcurrentHashMap   has 16 separate locks by
     default
 • Don’t reinvent the wheel
ReadWriteLocks

• Pair of locks
• Read lock can be held by multiple
  threads if there are no writers
• Write lock is exclusive
• Good improvements if object as fewer
  writers
Atomic Variables

• Allow to make check-update type of
  operations atomically
• Without locks - use low-level CPU
  instructions
• It’s   volatile   on steroids (visibility +
  atomicity)
Immutable Objects
•   Immutability makes concurrency simple - thread-
    safety guaranteed
•   An immutable object is:
    - final
    -   fields are final and private
    -   Constructor constructs the object completely
    -   No state changing methods
    -   Copy internal mutable objects when receiving
        or returning
JVM issues
•   Caching is useful - storing stuff in memory
•   Larger JVM heap size means longer garbage
    collection times
•   Not acceptable to have long pauses
•   Solutions
    -   Maximum size for heap 2GB/4GB
    -   Multiple JVMs per machine
    -   Better garbage collectors: G1 might help
Scaling Up: Other
        Approaches
• Change the paradigm
 - Actors (Erlang and Scala)
 - Dataflow programming (GParallelizer)
 - Software Transactional Memory
     (Pastrami)
 -   Functional languages, such as Clojure
Scaling Up: Other
        Approaches
• Dedicated JVM-friendly hardware
 - Azul Systems is amazing
 - Hundreds of cores
 - Enormous heap sizes with negligible gc
     pauses
 -   HTM included
 -   Built-in lock elision mechanism
Horizontal Scalability
Horizontal Scalability
       The hard part
Horizontal Scalability
               Scale Out


• Big machines are expensive - 1 x 32 core
  normally much more expensive than 4 x
  8 core
• Increase throughput by adding more
  machines
• Distributed Systems research revisited -
  not new
Requirements

• Scalability
• Availability
• Reliability
• Performance
Typical Server Architecture
... # of users increases
... and increases
... too much load
... and we loose availability
... so we add servers
... and a load balancer
... and another one rides the bus
... we create a DB cluster
... and we cache wherever we can



              Cache




              Cache
Challenges

• How do we route requests to servers?
• How do distribute data between servers?
• How do we handle failures?
• How do we keep our cache consistent?
• How do we handle load peaks?
Technique #1: Partitioning



  A     F      K      P     U
  ...   ...    ...    ...   ...
  E      J     O      T     Z

              Users
Technique #1: Partitioning

  • Each server handles a subset of data
  • Improves scalability by parallelizing
  • Requires predictable routing
  • Introduces problems with locality
  • Move work to where the data is!
Technique #2: Replication

Active




Backup
Technique #2: Replication

  • Keep copies of data/state in multiple
    servers
  • Used for fail-over - increases availability
  • Requires more cold hardware
  • Overhead of replicating might reduce
    performance
Technique #3: Messaging
Technique #3: Messaging
 • Use message passing, queues and pub/sub
   models - JMS
 • Improves reliability easily
 • Helps deal with peaks
  - The queue keeps filling
  - If it gets too big, extra requests are
     rejected
Solution #1: De-
      normalize DB
• Faster queries
• Additional work to generate tables
• Less space efficiency
• Harder to maintain consistency
Solution #2: Non-SQL
       Database

• Why not remove the relational part
  altogether
• Bad for complex queries
• Berkeley DB is a prime example
Solution #3: Distributed
       Key/Value Stores
•   Highly scalable - used in the largest websites in the
    world, based on Amazon’s Dynamo and Google’s
    BigTable
•   Mostly open source
•   Partitioned
•   Replicated
•   Versioned
•   No SPOF
•   Voldemort (LinkedIn), Cassandra (Facebook) and HBase
    are written in Java
Solution #4:
MapReduce




    Map...
Solution #4:
MapReduce




    Map...
Solution #4:
MapReduce


               Divide Work




    Map...
Solution #4:
MapReduce


               Divide Work




    Map...
Solution #4:
MapReduce


               Divide Work




    Map...
Solution #4:
MapReduce




    Map...
Solution #4:
MapReduce


               Compute




    Map...
Solution #4:
MapReduce

               Return and
                aggregate




   Reduce...
Solution #4:
MapReduce

               Return and
                aggregate




   Reduce...
Solution #4:
MapReduce

               Return and
                aggregate




   Reduce...
Solution #4:
          MapReduce
• Google’s algorithm to split work, process it
  and reduce to an answer
• Used for offline processing of large
  amounts of data
• Hadoop is used everywhere! Other options
  such as GridGain exist
Solution #5: Data Grid
• Data (and computations)
• In-memory - low response times
• Database back-end (SQL or not)
• Partitioned - operations on data executed in
  specific partition
• Replicated - handles failover automatically
• Transactional
Solution #5: Data Grid
• It’s a distributed cache + computational
  engine
• Can be used as a cache with JPA and the like
• Oracle Coherence is very good.
• Terracotta, Gridgain, Gemfire, Gigaspaces,
  Velocity (Microsoft) and Websphere
  extreme scale (IBM)
Retrospective

• You need to scale up and out
• Write code thinking of hundreds of cores
• Relational might not be the way to go
• Cache whenever you can
• Be aware of data locality
Q &A
Thanks for listening!




                       Ruben Badaró
                http://www.zonaj.org

More Related Content

What's hot (20)

PDF
Tech Talk: RocksDB Slides by Dhruba Borthakur & Haobo Xu of Facebook
The Hive
 
PDF
Hadoop Architecture and HDFS
Edureka!
 
PPTX
The Impala Cookbook
Cloudera, Inc.
 
PDF
Diagnosing Problems in Production - Cassandra
Jon Haddad
 
PDF
Process Management
Christalin Nelson
 
PPT
Power_780+(9179-MHD)표준제안서
기한 김
 
PDF
High Concurrency Architecture at TIKI
Nghia Minh
 
PDF
Iceberg: A modern table format for big data (Strata NY 2018)
Ryan Blue
 
PDF
Mastering GC.pdf
Jean-Philippe BEMPEL
 
PPTX
BI, Reporting and Analytics on Apache Cassandra
Victor Coustenoble
 
PDF
Apache Iceberg: An Architectural Look Under the Covers
ScyllaDB
 
PPTX
DNS Security Presentation ISSA
Srikrupa Srivatsan
 
PPTX
Admission Control in Impala
Cloudera, Inc.
 
PDF
Threat Detection and Response at Scale with Dominique Brezinski
Databricks
 
PDF
Apache Ratis - In Search of a Usable Raft Library
Tsz-Wo (Nicholas) Sze
 
PDF
Apache Zookeeper
Nguyen Quang
 
PPTX
Maria DB Galera Cluster for High Availability
OSSCube
 
PDF
MyRocks Deep Dive
Yoshinori Matsunobu
 
PDF
MySQL High Availability Solutions
Mydbops
 
PDF
Best Practice for Achieving High Availability in MariaDB
MariaDB plc
 
Tech Talk: RocksDB Slides by Dhruba Borthakur & Haobo Xu of Facebook
The Hive
 
Hadoop Architecture and HDFS
Edureka!
 
The Impala Cookbook
Cloudera, Inc.
 
Diagnosing Problems in Production - Cassandra
Jon Haddad
 
Process Management
Christalin Nelson
 
Power_780+(9179-MHD)표준제안서
기한 김
 
High Concurrency Architecture at TIKI
Nghia Minh
 
Iceberg: A modern table format for big data (Strata NY 2018)
Ryan Blue
 
Mastering GC.pdf
Jean-Philippe BEMPEL
 
BI, Reporting and Analytics on Apache Cassandra
Victor Coustenoble
 
Apache Iceberg: An Architectural Look Under the Covers
ScyllaDB
 
DNS Security Presentation ISSA
Srikrupa Srivatsan
 
Admission Control in Impala
Cloudera, Inc.
 
Threat Detection and Response at Scale with Dominique Brezinski
Databricks
 
Apache Ratis - In Search of a Usable Raft Library
Tsz-Wo (Nicholas) Sze
 
Apache Zookeeper
Nguyen Quang
 
Maria DB Galera Cluster for High Availability
OSSCube
 
MyRocks Deep Dive
Yoshinori Matsunobu
 
MySQL High Availability Solutions
Mydbops
 
Best Practice for Achieving High Availability in MariaDB
MariaDB plc
 

Viewers also liked (20)

PDF
MapReduce Debates and Schema-Free
hybrid cloud
 
PPTX
Java tips
Viswanath Lekshmanan
 
PPT
Optimizing your java applications for multi core hardware
IndicThreads
 
PPTX
Operations-Driven Web Services at Rent the Runway
Camille Fournier
 
PPT
Securing Java EE Web Apps
Frank Kim
 
PPS
Web20expo Scalable Web Arch
mclee
 
PDF
Cuestionario internet Hernandez Michel
jhonzmichelle
 
PPTX
Scalable Application Development on AWS
Mikalai Alimenkou
 
PPT
Building a Scalable XML-based Dynamic Delivery Architecture: Standards and Be...
Jerry SILVER
 
PDF
Highly Scalable Java Programming for Multi-Core System
James Gan
 
PPTX
Scalable Applications with Scala
Nimrod Argov
 
KEY
Intro to Erlang
Ken Pratt
 
PPTX
Building Highly Scalable Java Applications on Windows Azure - JavaOne S313978
David Chou
 
PPT
Diary of a Scalable Java Application
Martin Jackson
 
PDF
Java scalability considerations yogesh deshpande
IndicThreads
 
PDF
Scalable web architecture
Kaushik Paranjape
 
PPTX
Scalable Java Application Development on AWS
Mikalai Alimenkou
 
PDF
Apache Cassandra Lesson: Data Modelling and CQL3
Markus Klems
 
PPTX
The Java memory model made easy
Rafael Winterhalter
 
MapReduce Debates and Schema-Free
hybrid cloud
 
Optimizing your java applications for multi core hardware
IndicThreads
 
Operations-Driven Web Services at Rent the Runway
Camille Fournier
 
Securing Java EE Web Apps
Frank Kim
 
Web20expo Scalable Web Arch
mclee
 
Cuestionario internet Hernandez Michel
jhonzmichelle
 
Scalable Application Development on AWS
Mikalai Alimenkou
 
Building a Scalable XML-based Dynamic Delivery Architecture: Standards and Be...
Jerry SILVER
 
Highly Scalable Java Programming for Multi-Core System
James Gan
 
Scalable Applications with Scala
Nimrod Argov
 
Intro to Erlang
Ken Pratt
 
Building Highly Scalable Java Applications on Windows Azure - JavaOne S313978
David Chou
 
Diary of a Scalable Java Application
Martin Jackson
 
Java scalability considerations yogesh deshpande
IndicThreads
 
Scalable web architecture
Kaushik Paranjape
 
Scalable Java Application Development on AWS
Mikalai Alimenkou
 
Apache Cassandra Lesson: Data Modelling and CQL3
Markus Klems
 
The Java memory model made easy
Rafael Winterhalter
 
Ad

Similar to Writing Scalable Software in Java (20)

PDF
Scalability, Availability & Stability Patterns
Jonas Bonér
 
PDF
Scalability broad strokes
Gagan Bajpai
 
PPT
The economies of scaling software - Abdel Remani
jaxconf
 
PPT
The Economies of Scaling Software
Abdelmonaim Remani
 
PPT
Bhupeshbansal bigdata
Bhupesh Bansal
 
PDF
Jay Kreps on Project Voldemort Scaling Simple Storage At LinkedIn
LinkedIn
 
PDF
Voldemort Nosql
elliando dias
 
PDF
System Design Interview Questions PDF By ScholarHat
Scholarhat
 
PPTX
Intro to Big Data and NoSQL
Don Demcsak
 
KEY
What ya gonna do?
CQD
 
PPTX
JAZOON'13 - Abdelmonaim Remani - The Economies of Scaling Software
jazoon13
 
PDF
Challenges in Maintaining a High Performance Search Engine Written in Java
lucenerevolution
 
PDF
Concurrency and Multithreading Demistified - Reversim Summit 2014
Haim Yadid
 
PDF
SQL? NoSQL? NewSQL?!? What’s a Java developer to do? - JDC2012 Cairo, Egypt
Chris Richardson
 
PPT
UnConference for Georgia Southern Computer Science March 31, 2015
Christopher Curtin
 
PPT
SQL or NoSQL, that is the question!
Andraz Tori
 
PPT
Silicon India Java Conference: Building Scalable Solutions For Commerce Silic...
Kalaiselvan (Selvan)
 
PPTX
Big Data (NJ SQL Server User Group)
Don Demcsak
 
PDF
Hpc lunch and learn
John D Almon
 
PPTX
Microsoft Openness Mongo DB
Heriyadi Janwar
 
Scalability, Availability & Stability Patterns
Jonas Bonér
 
Scalability broad strokes
Gagan Bajpai
 
The economies of scaling software - Abdel Remani
jaxconf
 
The Economies of Scaling Software
Abdelmonaim Remani
 
Bhupeshbansal bigdata
Bhupesh Bansal
 
Jay Kreps on Project Voldemort Scaling Simple Storage At LinkedIn
LinkedIn
 
Voldemort Nosql
elliando dias
 
System Design Interview Questions PDF By ScholarHat
Scholarhat
 
Intro to Big Data and NoSQL
Don Demcsak
 
What ya gonna do?
CQD
 
JAZOON'13 - Abdelmonaim Remani - The Economies of Scaling Software
jazoon13
 
Challenges in Maintaining a High Performance Search Engine Written in Java
lucenerevolution
 
Concurrency and Multithreading Demistified - Reversim Summit 2014
Haim Yadid
 
SQL? NoSQL? NewSQL?!? What’s a Java developer to do? - JDC2012 Cairo, Egypt
Chris Richardson
 
UnConference for Georgia Southern Computer Science March 31, 2015
Christopher Curtin
 
SQL or NoSQL, that is the question!
Andraz Tori
 
Silicon India Java Conference: Building Scalable Solutions For Commerce Silic...
Kalaiselvan (Selvan)
 
Big Data (NJ SQL Server User Group)
Don Demcsak
 
Hpc lunch and learn
John D Almon
 
Microsoft Openness Mongo DB
Heriyadi Janwar
 
Ad

Recently uploaded (20)

PPTX
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
PDF
UiPath Agentic AI ile Akıllı Otomasyonun Yeni Çağı
UiPathCommunity
 
PDF
5 Things to Consider When Deploying AI in Your Enterprise
Safe Software
 
PDF
Redefining Work in the Age of AI - What to expect? How to prepare? Why it mat...
Malinda Kapuruge
 
PPTX
reInforce 2025 Lightning Talk - Scott Francis.pptx
ScottFrancis51
 
PPTX
𝙳𝚘𝚠𝚗𝚕𝚘𝚊𝚍—Wondershare Filmora Crack 14.0.7 + Key Download 2025
sebastian aliya
 
PDF
ArcGIS Utility Network Migration - The Hunter Water Story
Safe Software
 
PDF
LLM Search Readiness Audit - Dentsu x SEO Square - June 2025.pdf
Nick Samuel
 
PDF
Optimizing the trajectory of a wheel loader working in short loading cycles
Reno Filla
 
PDF
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 
PDF
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
Earley Information Science
 
PDF
Database Benchmarking for Performance Masterclass: Session 1 - Benchmarking F...
ScyllaDB
 
PPTX
01_Approach Cyber- DORA Incident Management.pptx
FinTech Belgium
 
PPTX
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Pitch ...
Michele Kryston
 
PDF
Automating the Geo-Referencing of Historic Aerial Photography in Flanders
Safe Software
 
PDF
Darley - FIRST Copenhagen Lightning Talk (2025-06-26) Epochalypse 2038 - Time...
treyka
 
PDF
Java 25 and Beyond - A Roadmap of Innovations
Ana-Maria Mihalceanu
 
PPTX
Smarter Governance with AI: What Every Board Needs to Know
OnBoard
 
PDF
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
PDF
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
 
UserCon Belgium: Honey, VMware increased my bill
stijn40
 
UiPath Agentic AI ile Akıllı Otomasyonun Yeni Çağı
UiPathCommunity
 
5 Things to Consider When Deploying AI in Your Enterprise
Safe Software
 
Redefining Work in the Age of AI - What to expect? How to prepare? Why it mat...
Malinda Kapuruge
 
reInforce 2025 Lightning Talk - Scott Francis.pptx
ScottFrancis51
 
𝙳𝚘𝚠𝚗𝚕𝚘𝚊𝚍—Wondershare Filmora Crack 14.0.7 + Key Download 2025
sebastian aliya
 
ArcGIS Utility Network Migration - The Hunter Water Story
Safe Software
 
LLM Search Readiness Audit - Dentsu x SEO Square - June 2025.pdf
Nick Samuel
 
Optimizing the trajectory of a wheel loader working in short loading cycles
Reno Filla
 
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 
EIS-Webinar-Engineering-Retail-Infrastructure-06-16-2025.pdf
Earley Information Science
 
Database Benchmarking for Performance Masterclass: Session 1 - Benchmarking F...
ScyllaDB
 
01_Approach Cyber- DORA Incident Management.pptx
FinTech Belgium
 
MARTSIA: A Tool for Confidential Data Exchange via Public Blockchain - Pitch ...
Michele Kryston
 
Automating the Geo-Referencing of Historic Aerial Photography in Flanders
Safe Software
 
Darley - FIRST Copenhagen Lightning Talk (2025-06-26) Epochalypse 2038 - Time...
treyka
 
Java 25 and Beyond - A Roadmap of Innovations
Ana-Maria Mihalceanu
 
Smarter Governance with AI: What Every Board Needs to Know
OnBoard
 
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
Salesforce Summer '25 Release Frenchgathering.pptx.pdf
yosra Saidani
 

Writing Scalable Software in Java

  • 1. Writing Scalable Software in Java From multi-core to grid-computing
  • 2. Me • Ruben Badaró • Dev Expert at Changingworlds/Amdocs • PT.JUG Leader • http://www.zonaj.org
  • 3. What this talk is not about • Sales pitch • Cloud Computing • Service Oriented Architectures • Java EE • How to write multi-threaded code
  • 4. Summary • Define Performance and Scalability • Vertical Scalability - scaling up • Horizontal Scalability - scaling out • Q&A
  • 6. Performance Amount of useful work accomplished by a computer system compared to the time and resources used
  • 7. Scalability Capability of a system to increase the amount of useful work as resources and load are added to the system
  • 8. Scalability • A system that performs fast with 10 users might not do so with 1000 - it doesn’t scale • Designing for scalability always decreases performance
  • 12. Scalability is about parallelizing • Parallel decomposition allows division of work • Parallelizing might mean more work • There’s almost always a part of serial computation
  • 14. Vertical Scalability Somewhat hard
  • 15. Vertical Scalability Scale Up • Bigger, meaner machines - More cores (and more powerful) - More memory - Faster local storage • Limited - Technical constraints - Cost - big machines get exponentially expensive
  • 16. Shared State • Need to use those cores • Java - shared-state concurrency - Mutable state protected with locks - Hard to get right - Most developers don’t have experience writing multithreaded code
  • 17. This is how they look like public static synchronized SomeObject getInstance() { return instance; } public SomeObject doConcurrentThingy() { synchronized(this) { //... } return ..; }
  • 18. Single vs Multi-threaded • Single-threaded - No scheduling cost - No synchronization cost • Multi-threaded - Context Switching (high cost) - Memory Synchronization (memory barriers) - Blocking
  • 19. Lock Contention Little’s Law The average number of customers in a stable system is equal to their average arrival rate multiplied by their average time in the system
  • 20. Reducing Contention • Reduce lock duration • Reduce frequency with which locks are requested (stripping) • Replace exclusive locks with other mechanisms - Concurrent Collections - ReadWriteLocks - Atomic Variables - Immutable Objects
  • 21. Concurrent Collections • Use lock stripping • Includes putIfAbsent() and replace() methods • ConcurrentHashMap has 16 separate locks by default • Don’t reinvent the wheel
  • 22. ReadWriteLocks • Pair of locks • Read lock can be held by multiple threads if there are no writers • Write lock is exclusive • Good improvements if object as fewer writers
  • 23. Atomic Variables • Allow to make check-update type of operations atomically • Without locks - use low-level CPU instructions • It’s volatile on steroids (visibility + atomicity)
  • 24. Immutable Objects • Immutability makes concurrency simple - thread- safety guaranteed • An immutable object is: - final - fields are final and private - Constructor constructs the object completely - No state changing methods - Copy internal mutable objects when receiving or returning
  • 25. JVM issues • Caching is useful - storing stuff in memory • Larger JVM heap size means longer garbage collection times • Not acceptable to have long pauses • Solutions - Maximum size for heap 2GB/4GB - Multiple JVMs per machine - Better garbage collectors: G1 might help
  • 26. Scaling Up: Other Approaches • Change the paradigm - Actors (Erlang and Scala) - Dataflow programming (GParallelizer) - Software Transactional Memory (Pastrami) - Functional languages, such as Clojure
  • 27. Scaling Up: Other Approaches • Dedicated JVM-friendly hardware - Azul Systems is amazing - Hundreds of cores - Enormous heap sizes with negligible gc pauses - HTM included - Built-in lock elision mechanism
  • 29. Horizontal Scalability The hard part
  • 30. Horizontal Scalability Scale Out • Big machines are expensive - 1 x 32 core normally much more expensive than 4 x 8 core • Increase throughput by adding more machines • Distributed Systems research revisited - not new
  • 33. ... # of users increases
  • 35. ... too much load
  • 36. ... and we loose availability
  • 37. ... so we add servers
  • 38. ... and a load balancer
  • 39. ... and another one rides the bus
  • 40. ... we create a DB cluster
  • 41. ... and we cache wherever we can Cache Cache
  • 42. Challenges • How do we route requests to servers? • How do distribute data between servers? • How do we handle failures? • How do we keep our cache consistent? • How do we handle load peaks?
  • 43. Technique #1: Partitioning A F K P U ... ... ... ... ... E J O T Z Users
  • 44. Technique #1: Partitioning • Each server handles a subset of data • Improves scalability by parallelizing • Requires predictable routing • Introduces problems with locality • Move work to where the data is!
  • 46. Technique #2: Replication • Keep copies of data/state in multiple servers • Used for fail-over - increases availability • Requires more cold hardware • Overhead of replicating might reduce performance
  • 48. Technique #3: Messaging • Use message passing, queues and pub/sub models - JMS • Improves reliability easily • Helps deal with peaks - The queue keeps filling - If it gets too big, extra requests are rejected
  • 49. Solution #1: De- normalize DB • Faster queries • Additional work to generate tables • Less space efficiency • Harder to maintain consistency
  • 50. Solution #2: Non-SQL Database • Why not remove the relational part altogether • Bad for complex queries • Berkeley DB is a prime example
  • 51. Solution #3: Distributed Key/Value Stores • Highly scalable - used in the largest websites in the world, based on Amazon’s Dynamo and Google’s BigTable • Mostly open source • Partitioned • Replicated • Versioned • No SPOF • Voldemort (LinkedIn), Cassandra (Facebook) and HBase are written in Java
  • 54. Solution #4: MapReduce Divide Work Map...
  • 55. Solution #4: MapReduce Divide Work Map...
  • 56. Solution #4: MapReduce Divide Work Map...
  • 58. Solution #4: MapReduce Compute Map...
  • 59. Solution #4: MapReduce Return and aggregate Reduce...
  • 60. Solution #4: MapReduce Return and aggregate Reduce...
  • 61. Solution #4: MapReduce Return and aggregate Reduce...
  • 62. Solution #4: MapReduce • Google’s algorithm to split work, process it and reduce to an answer • Used for offline processing of large amounts of data • Hadoop is used everywhere! Other options such as GridGain exist
  • 63. Solution #5: Data Grid • Data (and computations) • In-memory - low response times • Database back-end (SQL or not) • Partitioned - operations on data executed in specific partition • Replicated - handles failover automatically • Transactional
  • 64. Solution #5: Data Grid • It’s a distributed cache + computational engine • Can be used as a cache with JPA and the like • Oracle Coherence is very good. • Terracotta, Gridgain, Gemfire, Gigaspaces, Velocity (Microsoft) and Websphere extreme scale (IBM)
  • 65. Retrospective • You need to scale up and out • Write code thinking of hundreds of cores • Relational might not be the way to go • Cache whenever you can • Be aware of data locality
  • 66. Q &A Thanks for listening! Ruben Badaró http://www.zonaj.org