DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Because the DevOps movement has redefined engineering responsibilities, SREs now have to become stewards of observability strategy.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Related

  • How To Build a Google Photos Clone - Part 1
  • Build a Java Backend That Connects With Salesforce
  • How to Develop Event-Driven Architectures
  • Build Even Faster Quarkus Applications With fast-jar

Trending

  • Domain-Centric Agile Modeling for Legacy Insurance Systems
  • Yet Another GenAI Nightmare: Seven Shadow AI Pitfalls to Avoid
  • Simplifying Multi-LLM Integration With KubeMQ
  • Optimizing Software Performance for High-Impact Asset Management Systems
  1. DZone
  2. Coding
  3. Java
  4. How to Build Scalable, Stateful Java Services in Under 15 Minutes

How to Build Scalable, Stateful Java Services in Under 15 Minutes

Learn more about building scalable Java services in 15 minutes or less.

By 
Bradley Johnson user avatar
Bradley Johnson
·
Updated Jun. 19, 19 · Tutorial
Likes (5)
Comment
Save
Tweet
Share
14.3K Views

Join the DZone community and get the full member experience.

Join For Free

Five years ago, when I started tracking media buzz around stateful architectures, I’d see a few articles every month about running stateful containers. That's about when Caitie McCaffrey first shared this awesome presentation about building scalable stateful architectures. Since then, the dominant software paradigm has become functional application design. The actor model and other object-oriented paradigms are still in use, but database-centric RESTful architectures are standard means of building web applications today.

However, the tides are beginning to shift. Due to innovations like the blockchain, growing demand for real-time applications, the digitization of OT assets, and the proliferation of cheap compute resources at the network edge; there’s renewed interest in decentralized application architectures. As such, there’s also been increased focus on stateful applications. For example, at least five Apache Foundation projects (Beam, Flink, Spark, Samza, and TomEE) are touting statefulness as a benefit today. Modern applications communicate across multiple application silos and must span real-world machines, devices, and distributed data centers around the world. Stateful application architectures provide a way to abstract away the logistical effort of state management, thereby reducing development and management effort necessary to operate massive-scale distributed applications.

Build a Scalable, Stateful To-Do List in 15 Minutes or Less

For the rest of this post, I want to disprove the notion that building scalable, stateful applications is a task too complex for everyday Java developers. In order to illustrate how easily a stateful application can be set up, we’ll walk through a tutorial for building a simple to-do list using the Swim platform. You can find all the source code for the to-do list tutorial here on GitHub.

Getting Started: Setting Up Your Development Environment

Before diving into the to-do list app itself, it’s important to ensure your development environment is properly set up to run Swim applications.

To run the to-do list example application, only Java 9 and the Gradle build tool (which is included in the wrapper script) are required. This video tutorial goes through the process of setting up your local Swim development environment:


Tutorial: How to Build a Simple, Stateful “To-Do List” App Using Swim

Once your development environment is set up, you’re ready to build a stateful to-do list. The to-do list example is quite basic, but the same patterns can be applied to Swim applications of any complexity. As I mentioned earlier in the post, all the code for the to-do list example app is available on GitHub.

For a better idea of what's included in this tutorial, take a look at the following lines of server code. This code block defines a Web Agent that can create and observe a to-do list. Every server-side to-do list continuously and statefully runs the logic below:

/**
 * This is a simple WebAgent to manage the list of items in the To-do list
 */
public class ListAgent extends AbstractAgent {

  /**
   * This MapLane holds each list item and uses a timestamp for a unique key
   */
  @SwimLane("list")
  MapLane<Long, String> todoList = this.<Long, String>mapLane();

  /**
   * This is a command lane used to add new items to the to-do list
   */
  @SwimLane("addListItem")
  public CommandLane<String> addListItem = this.<String>commandLane()
    .onCommand((String newListItem) -> {
      // create a new timestamp as our UUID
      final long newUuid = System.currentTimeMillis();
      // cap item length to 255 characters
      newListItem = newListItem.substring(0, Math.min(newListItem.length(), 255));

      // add the new item to the todoList MapLane
      todoList.put(newUuid, newListItem);
    });

  /**
   * This is a command lane used to remove items from the 
   * to-do list by its key (or uuid)
   */
  @SwimLane("removeListItem")
  public CommandLane<String> removeListItem = this.<String>commandLane()
    .onCommand((String uuidString) -> {
      // parse the value sent by the UI from a String to Long
      long uuidToRemove = Long.parseLong(uuidString);

      // remove the list item from the todoList MapLane
      todoList.remove(uuidToRemove);
    });
}


Finally, if you’re ready to get started building your own stateful to-do list application, check out this tutorial video:


Learn More

Let us know your thoughts about this tutorial and what you're building on the open-source Swim platform. You can get started with Swim here and make sure to STAR us on GitHub.

application Build (game engine) Java (programming language) Architecture

Published at DZone with permission of Bradley Johnson. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • How To Build a Google Photos Clone - Part 1
  • Build a Java Backend That Connects With Salesforce
  • How to Develop Event-Driven Architectures
  • Build Even Faster Quarkus Applications With fast-jar

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!