Space-Based Architecture
In the ever-evolving landscape of software architecture, Space-Based Architecture has emerged as a powerful approach to building microservices-based systems. It offers an innovative solution that leverages the concept of Tuple Spaces, distributed caching, and in-memory data grids to create highly scalable and elastic systems. In this blog post, we will delve into the core concepts of Space-Based Architecture and when it is best suited for your projects.
Overview
Space-Based Architecture centers around the concept of Tuple Spaces, which are essentially shared memory spaces among multiple parallel processors. Tuples within these spaces contain data with zero or more arguments and a key. One of the distinguishing features is that all transactional data is cached in memory, enabling rapid data access and sharing among microservices.
Key Components
- In-Memory Data Grid (IMDG): An IMDG is a networked cluster of computers that pool their random access memory (RAM) to allow applications to share data across multiple instances. This facilitates fast and efficient data retrieval and sharing.
- Data Replication Engine: The data replication engine employs primary-copy and configurable lazy replication techniques. Each data entry is mapped to a single partition and replicated across multiple instances. The core data structure used is a Replicated Map, which ensures data consistency by replicating data to all members rather than partitioning it.
Every data movement in Space-Based Architecture is eventually consistent, and the replication between IMDG instances happens extremely fast, typically within the 10th or 100th of a second.
Scenarios of Space-Based Architecture
Let’s explore two key scenarios that highlight the advantages of Space-Based Architecture:
Scenario 1: Real-time Data Processing
When a request to create a customer is accepted by instance A of the customer service, the business logic pushes the request payload into the IMDG. The data replication engine then replicates this content across the cache cluster, making it visible to instance B.
Simultaneously, instance A asynchronously pushes an event into a message queue or topic (e.g., RabbitMQ or Kafka). On the consumer side of the queue/topic, there is a database writer service responsible for saving the record in the Customer database.
Scenario 2: Cold Start and Archive Retrieval
In situations where it’s necessary to recreate the cache during archive retrieval or system cold start, the DB reader service queries all data from the Customer database and pushes it into a queue/topic.
Connectors of the IMDG can consume data from this queue/topic, which, in turn, unlocks the cache for Customer service to serve requests efficiently.
When to Use Space-Based Architecture
Space-based architecture is particularly well-suited for the following scenarios:
- Highly Elastic and Scalable Systems: When you need to design systems that are highly elastic and can scale from 20 to 200,000 users in milliseconds without creating an excessive number of concurrent database connections.
- Handling Large Concurrent User Loads: When your system is expected to handle more than 1 million concurrent users efficiently, without the need for a corresponding increase in database connections.
When Not to Use Space-Based Architecture
While Space-Based Architecture offers many benefits, it may not be the best choice in certain situations:
- Large Transaction Volumes: If your system involves exceptionally large transaction volumes, it might be more complex to implement Space-Based Architecture.
- Avoiding Technical Complexity: If you prefer a simpler architecture or are not comfortable with the technical intricacies of Space-Based Architecture, other options may be more suitable.
- Absolute Data Synchronization: If your application requires absolute data synchronization between all instances at all times, Space-Based Architecture’s eventual consistency model may not align with your needs.
Conclusion
Space-Based Architecture is a robust solution for building microservices-based systems that demand high scalability, elasticity, and rapid data sharing. By understanding the core principles and scenarios of Space-Based Architecture, you can make an informed decision about whether it’s the right fit for your project. In the age of ever-growing data and user demands, this architecture can be a game-changer for your applications.