Backend Development 6 min read

Techniques for Achieving High Concurrency: Optimistic Lock, Read‑Write Splitting, CDN, Caching, and Load Balancing

The article explains how high‑concurrency systems can be built by decomposing workloads through optimistic locking, read‑write database splitting, resource separation with CDN acceleration, dynamic‑to‑static conversion, caching, and load‑balancing strategies, providing practical code examples for each technique.

Architecture Digest
Architecture Digest
Architecture Digest
Techniques for Achieving High Concurrency: Optimistic Lock, Read‑Write Splitting, CDN, Caching, and Load Balancing

Server performance, database performance, network latency, and even programming language choices affect the maximum concurrent requests a system can handle; the common solution is to split responsibilities as finely as possible.

Optimistic Lock – a classic database optimization that uses a version field to prevent dirty reads without exclusive locks. Example table definition and Java entity annotations:

CREATE TABLE tbl (
    id VARCHAR(32),
    optimistic_lock NUMERIC(12) -- version field
);

@Version
@Column(name = "optimistic_lock", columnDefinition = "INTEGER")
private long optimisticLock;

Read/Write Splitting – separating master (write) and slave (read) databases, often configured with two data sources in Spring:

<!-- Define data source, using a custom implementation -->
<bean id="dataSource" class="cn.itcast.usermanage.spring.DynamicDataSource">
    <!-- Set multiple data sources -->
    <property name="targetDataSources">
        <map key-type="java.lang.String">
            <!-- Keys must match those used in code -->
            <entry key="master" value-ref="masterDataSource"/>
            <entry key="slave" value-ref="slave01DataSource"/>
        </map>
    </property>
    <!-- Default to the write (master) data source -->
    <property name="defaultTargetDataSource" ref="masterDataSource"/>
</bean>

DAO methods then choose the appropriate source for reads or writes, and master/slave servers synchronize to keep data consistent.

Resource Separation & CDN Acceleration – static assets such as images, JavaScript, CSS, or ZIP files are stored on separate servers or CDNs, reducing load on the main application server and bringing content closer to users.

Dynamic‑to‑Static Conversion – for idempotent requests, pre‑compute results (e.g., daily batch jobs that calculate each user’s monthly transaction total) and serve the cached static data directly, eliminating the calculation step at request time.

Cache – another form of dynamic‑to‑static, typically a key‑value store in memory. Example using MemCachedClient:

MemCachedClient mc = new MemCachedClient();
String key = "cacheKey1";
Object value = SomeClass.getObject();
mc.set(key, value);

Server Mirroring & Load Balancing – deploying multiple server instances (mirrors) across regions or ISPs, then distributing traffic based on load. Example Tomcat connector configuration for two instances:

<Connector port="11009" protocol="AJP/1.3" redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat1">
    <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
</Engine>

<Connector port="12009" protocol="AJP/1.3" redirectPort="8443" />
<Engine name="Catalina" defaultHost="localhost" jvmRoute="tomcat2">
    <Cluster className="org.apache.catalina.ha.tcp.SimpleTcpCluster"/>
</Engine>

Additional considerations include database sharding, proper synchronization, and basic SQL optimizations such as avoiding full‑table scans.

Source: https://www.v2ex.com/t/364701

Backendload balancingCachingCDNhigh concurrencyRead/Write Splittingoptimistic lock
Architecture Digest
Written by

Architecture Digest

Focusing on Java backend development, covering application architecture from top-tier internet companies (high availability, high performance, high stability), big data, machine learning, Java architecture, and other popular fields.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.