Production-grade guide to nft marketplace architecture covering architecture patterns, implementation strategies, testing approaches, and operational best practices for enterprise engineering teams.
An NFT marketplace architecture orchestrates the lifecycle of non-fungible tokens—from minting and listing to bidding, buying, and fulfilling ownership—across blockchain and off-chain systems. It matters when users expect instant, reliable, and transparent experiences in digital collectibles, art, gaming assets, or real estate, with high throughput, low latency, and resilience to blockchain congestion. This architecture integrates blockchain transaction layers with scalable, stateful services, real-time event processing, and efficient storage and retrieval of metadata.
To list an NFT, a user uploads metadata and sets a price, triggering a transaction that writes the listing to a smart contract on-chain. The process begins with a client sending a POST /listings request with a JSON body:
{
"tokenId": "0x1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2d3e4f5a6b7c8d9e0f1a2b",
"ownerAddress": "0x7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2d3e4f5a6b7c8d9e0f1a2b7c8d9e0f1a2b",
"priceInWei": "1000000000000000000",
"currency": "0x0000000000000000000000000000000000000000",
"durationInBlocks": 1000,
"royaltyBps": 500,
"metadataUri": "https://ipfs.example.com/ipfs/QmXyZ1234567890"
}
The backend service validates the tokenId against the blockchain using eth_getTransactionReceipt with blockHash and transactionHash. If the NFT is not yet minted, it calls eth_call on the ERC721 contract with function: "tokenURI(uint256)" and resolves the metadataUri via IPFS, fetching metadata.json from https://ipfs.example.com/ipfs/QmXyZ1234567890.
If the metadata fails to resolve, the system logs:
ERROR: Failed to resolve metadata for tokenId 0x1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2d3e4f5a6b7c8d9e0f1a2b
- IPFS error: 504 Gateway Timeout (https://ipfs.example.com/ipfs/QmXyZ1234567890)
- Fallback: using local metadata stored at /metadata/0x1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2d3e4f5a6b7c8d9e0f1a2b.json
The listing is then recorded in a PostgreSQL database with a listings table:
CREATE TABLE listings (
id BIGSERIAL PRIMARY KEY,
token_id BYTEA NOT NULL,
owner_address BYTEA NOT NULL,
price_in_wei NUMERIC NOT NULL,
currency_address BYTEA NOT NULL,
duration_in_blocks INT NOT NULL,
royalty_bps INT NOT NULL,
metadata_uri TEXT NOT NULL,
created_at TIMESTAMPTZ DEFAULT NOW(),
updated_at TIMESTAMPTZ DEFAULT NOW()
);
A CREATE INDEX CONCURRENTLY on token_id ensures fast lookups during listing queries.
When a buyer selects a listing, the frontend triggers a POST /buy with a signed transaction. The request body contains the txHash, buyerAddress, and signature:
{
"txHash": "0x8a9b0c1d2e3f4a5b6c7d8e9f0a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0",
"buyerAddress": "0x11223344556677889900aabbccddeeff11223344556677889900aabbccddeeff",
"signature": "0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"
}
The backend validates the signature using eth_signTypedData and checks the txHash via eth_getTransactionReceipt. If the transaction is not confirmed, it polls the node with eth_getTransactionReceipt every 5 seconds until status 0x1 (success) or 0x0 (failure), with a 30-second timeout.
On confirmation, the system updates the listing’s status to sold and logs:
INFO: NFT purchased: tokenId=0x1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2d3e4f5a6b7c8d9e0f1a2b, buyer=0x11223344556677889900aabbccddeeff11223344556677889900aabbccddeeff
- Payment: 1.0 ETH (1000000000000000000 wei) to seller: 0x7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2d3e4f5a6b7c8d9e0f1a2b7c8d9e0f1a2b
- Royalty: 500 BPS → 50,000,000,000,000,000 wei sent to creator
The royaltyBps field is used to compute the royalty amount: price_in_wei * royalty_bps / 10000. The royalty is then sent via a transfer call on the ERC20 contract with function: "transfer(address,uint256)", and the transaction is logged in a royalties table:
CREATE TABLE royalties (
id BIGSERIAL PRIMARY KEY,
listing_id BIGINT REFERENCES listings(id),
payment_tx_hash BYTEA NOT NULL,
amount_in_wei NUMERIC NOT NULL,
recipient_address BYTEA NOT NULL,
created_at TIMESTAMPTZ DEFAULT NOW()
);
Bidding introduces time-based auctions with multiple offers. The process starts with a POST /bids request:
{
"listingId": 12345,
"bidderAddress": "0x998877665544332211009988776655443322110099887766554433221100",
"amountInWei": "1500000000000000000",
"timestamp": "2024-05-10T12:34:56.789Z"
}
The backend checks the current highest bid in the bids table:
CREATE TABLE bids (
id BIGSERIAL PRIMARY KEY,
listing_id BIGINT REFERENCES listings(id),
bidder_address BYTEA NOT NULL,
amount_in_wei NUMERIC NOT NULL,
timestamp TIMESTAMPTZ NOT NULL,
created_at TIMESTAMPTZ DEFAULT NOW()
);
It ensures the bid is higher than the current highest bid using a SELECT ... FOR UPDATE lock, then inserts the new bid and updates the listings table’s current_bid_amount and last_bid_timestamp.
If the bid is not the highest, the system logs:
WARNING: Bid rejected on listing 12345: 1.5 ETH (1500000000000000000 wei) < current high: 1.7 ETH (1700000000000000000 wei)
- Bidder: 0x998877665544332211009988776655443322110099887766554433221100
- Timestamp: 2024-05-10T12:34:56.789Z
Bids are processed asynchronously. A bid-processor service listens to a Kafka topic bids.new with Avro-encoded messages, and when a bid is received, it updates the listing’s current_bid_amount via UPDATE listings SET current_bid_amount = ? WHERE id = ?.
After a sale or auction closes, the marketplace must transfer the NFT ownership on-chain. The fulfillment process is triggered by a cron job that checks the listings table for entries where status = 'sold' and fulfilled_at IS NULL.
The job runs every 10 seconds via systemctl:
[Unit]
Description=NFT Fulfillment Service
After=network.target
[Service]
Type=simple
ExecStart=/opt/nft-marketplace/bin/fulfillment
WorkingDirectory=/opt/nft-marketplace
User=app
Restart=always
[Install]
WantedBy=multi-user.target
When a listing is ready, the service calls eth_sendTransaction with a transfer transaction on the ERC721 contract:
{
"to": "0x11223344556677889900aabbccddeeff11223344556677889900aabbccddeeff",
"from": "0x7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2d3e4f5a6b7c8d9e0f1a2b7c8d9e0f1a2b",
"data": "0x23b872dd00000000000000000000000011223344556677889900aabbccddeeff11223344556677889900aabbccddeeff",
"value": "0",
"gas": 100000,
"gasPrice": "20000000000"
}
The data field encodes the transfer(address,uint256) function selector (0x23b872dd) and the tokenId (0x1122...). The service monitors the transaction receipt and updates the listings table with fulfilled_at and transaction_hash.
If the transaction fails, it logs:
ERROR: NFT transfer failed for listing 12345
- TxHash: 0x8a9b0c1d2e3f4a5b6c7d8e9f0a1b2c3d4e5f6a7b8c9d0e1f2a3b4c5d6e7f8a9b0
- Reason: ERC721: transfer to zero address
- Retry: scheduled in 60 seconds
Metadata resolution is a frequent failure point. When an NFT’s metadataUri is an IPFS CID, the system must resolve it via HTTP or IPFS gateway. If the gateway is down or slow, the metadata may be stale or missing entirely. A fallback mechanism uses a metadata_cache table to store local copies of metadata.json files, keyed by cid.
The metadata_cache table:
CREATE TABLE metadata_cache (
cid TEXT PRIMARY KEY,
content BYTEA NOT NULL,
fetched_at TIMESTAMPTZ DEFAULT NOW(),
expires_at TIMESTAMPTZ
);
The service checks metadata_cache before querying IPFS. If the cache is expired, it updates it and sets expires_at to NOW() + INTERVAL '1 day'.
Another silent failure is transaction confirmation delay. The system assumes that eth_getTransactionReceipt returns status = 0x1 after a block confirmation, but due to blockchain congestion, a transaction may be included in a block but not yet confirmed. The status field is 0x1 (success), but blockHash is 0x0000000000000000000000000000000000000000000000000000000000000000—indicating a pending transaction. The system must handle this by polling until blockHash is non-zero.
The tokenURI call can return invalid JSON or missing fields. The system validates that the response includes name, description, image, and attributes. If any field is missing, it logs:
WARNING: Invalid metadata for token 0x1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2d3e4f5a6b7c8d9e0f1a2b
- Missing: 'description'
- Extra: 'extra_field'
- Image URL: https://ipfs.example.com/ipfs/QmXyZ1234567890/image.png
The marketplace uses WebSocket connections to push updates to clients. On listing creation, the service publishes to a listings.created topic via Kafka. A webhook service listens to this topic and sends POST /webhooks to a configured endpoint:
{
"event": "listing.created",
"listingId": 12345,
"tokenId": "0x1a2b3c4d5e6f7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2d3e4f5a6b7c8d9e0f1a2b",
"ownerAddress": "0x7a8b9c0d1e2f3a4b5c6d7e8f9a0b1c2d3e4f5a6b7c8d9e0f1a2b7c8d9e0f1a2b",
"priceInWei": "1000000000000000000"
}
Clients subscribe to ws://marketplace.example.com/events and receive real-time updates. The server sends a JSON message on every state change:
{
"type": "listing.updated",
"data": {
"listingId": 12345,
"currentBid": "1200000000000000000",
"bidCount": 3,
"status": "active"
}
}
If the WebSocket connection drops, the client reconnects and sends a reconnect message with lastEventId, allowing the server to resume from that point.
The marketplace’s config.yaml file governs behavior across services:
nft:
blockchain:
rpc_url: "https://mainnet.infura.io/v3/abc123def456"
chain_id: 1
polling_interval: 5s
confirmation_threshold: 3
max_retries: 5
retry_backoff: "exponential"
storage:
ipfs:
gateway: "https://ipfs.example.com"
timeout: 10s
cache_ttl: 1h
postgres:
connection_string: "host=postgres user=marketplace password=secret dbname=nft"
pool_size: 20
idle_timeout: 300s
fulfillment:
batch_size: 10
batch_interval: 30s
retry_delay: 60s
webhooks:
base_url: "https://webhook.example.com"
max_retries: 3
retry_backoff: "linear"
The retry_backoff field supports exponential and linear strategies. The exponential strategy doubles the delay between retries, while linear adds a fixed offset.
A common operational confusion arises when confirmation_threshold is set to 3 but the blockchain confirms transactions in 5 blocks. The system may mark a listing as sold after 3 blocks, but the transaction is not yet final. The blockHash is correct, but confirmations is 2, leading to missed finality. The solution is to add a finality_check step that waits until confirmations >= confirmation_threshold.
Another edge case is when the metadata_uri is a URI that returns a redirect. The system must follow up to three redirects before parsing metadata.json, and if any redirect fails, it falls back to a local copy. The metadata_cache is updated with the final cid of the resolved file, not the original.
These details—concrete, repeatable, and grounded in real systems—define the architecture of an NFT marketplace, where every transaction, event, and metadata resolution is orchestrated across on-chain and off-chain layers, with precise, observable behaviors that surface silently in production.
This page was rewritten on 18 October 2026. It replaced a templated version that was not specific to its own title. How these pages are written and checked. If anything here is wrong, tell us at [email protected] and we will correct it.
We use cookies for analytics (Google Analytics) and advertising (Google AdSense) to improve your experience and support free content. Privacy Policy