-
Notifications
You must be signed in to change notification settings - Fork 402
blog: NEAR for Web2 Backend Developers: A Familiar Frontier #2595
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
Co-authored-by: Damián Parrino <[email protected]>
Co-authored-by: Damián Parrino <[email protected]>
@@ -0,0 +1,466 @@ | |||
# NEAR for Web2 Backend Developers: A Familiar Frontier | |||
|
|||
As an experienced backend developer, you're adept at building robust services, managing databases, and ensuring system reliability. When you hear "blockchain," it might sound like a completely different paradigm. However, platforms like [NEAR Protocol](/protocol/basics) are designed to be surprisingly accessible, offering a new kind of backend infrastructure that leverages many concepts you're already familiar with. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As an experienced backend developer, you're adept at building robust services, managing databases, and ensuring system reliability. When you hear "blockchain," it might sound like a completely different paradigm. However, platforms like [NEAR Protocol](/protocol/basics) are designed to be surprisingly accessible, offering a new kind of backend infrastructure that leverages many concepts you're already familiar with. | |
As an experienced backend developer, you're adept at building robust services, managing databases, and ensuring system reliability. When you hear "blockchain" it might sound like a completely different paradigm. However, platforms like [NEAR Protocol](/protocol/basics) are designed to be surprisingly accessible, offering a new kind of backend infrastructure that leverages many concepts you're already familiar with. |
docs/blog/near-for-backend-devs.md
Outdated
|
||
This article will guide you through understanding NEAR from a backend perspective. We'll explore how it can be seen as a decentralized, highly available backend platform where: | ||
|
||
* **Your Application's Backend Logic** lives in "[smart contracts](/smart-contracts/what-is)," which you can write in familiar languages like [Rust](/tools/sdk) (and others that compile to [WebAssembly](/smart-contracts/anatomy/wasm)). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* **Your Application's Backend Logic** lives in "[smart contracts](/smart-contracts/what-is)," which you can write in familiar languages like [Rust](/tools/sdk) (and others that compile to [WebAssembly](/smart-contracts/anatomy/wasm)). | |
* **Your Application's Backend Logic** lives in "[smart contracts](/smart-contracts/what-is)" which you can write in familiar languages like [Rust](/tools/sdk) (and others that compile to [WebAssembly](/smart-contracts/anatomy/wasm)). |
|
||
This article will guide you through understanding NEAR from a backend perspective. We'll explore how it can be seen as a decentralized, highly available backend platform where: | ||
|
||
* **Your Application's Backend Logic** lives in "[smart contracts](/smart-contracts/what-is)," which you can write in familiar languages like [Rust](/tools/sdk) (and others that compile to [WebAssembly](/smart-contracts/anatomy/)). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* **Your Application's Backend Logic** lives in "[smart contracts](/smart-contracts/what-is)," which you can write in familiar languages like [Rust](/tools/sdk) (and others that compile to [WebAssembly](/smart-contracts/anatomy/)). | |
* **Your Application's Backend Logic** lives in "[smart contracts](/smart-contracts/what-is)" which you can write in familiar languages like [Rust](/tools/sdk) (and others that compile to [WebAssembly](/smart-contracts/anatomy/)). |
On NEAR, each application (called a "smart contract" or just "contract") gets its own unique identifier, its [AccountId](/protocol/account-model) (e.g., `your-app.near`, `twitter-clone.your-account.near`). Think of this `AccountId` as a namespace for your application's dedicated state. | ||
|
||
* **Isolated State:** All data for your application is stored within the context of its `AccountId`. It's like having a dedicated key-value store or a NoSQL document database scoped specifically to your application. One application cannot directly tamper with the raw storage of another. | ||
* **Mutability with Control:** While the history of *changes* to this state is cryptographically secured and immutable (forming the blockchain), the *current state* of your application's data is indeed mutable. However, these mutations are not arbitrary. They can only occur by invoking the logic defined within your smart contract – your application's backend code. You define the rules for how state can change. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* **Mutability with Control:** While the history of *changes* to this state is cryptographically secured and immutable (forming the blockchain), the *current state* of your application's data is indeed mutable. However, these mutations are not arbitrary. They can only occur by invoking the logic defined within your smart contract – your application's backend code. You define the rules for how state can change. | |
* **Mutability with Control:** While the *history of changes* to this state is cryptographically secured and immutable (forming the blockchain), the *current state* of your application's data is indeed mutable. However, these mutations are not arbitrary. They can only occur by invoking the logic defined within your smart contract – your application's backend code. You define the rules for how the state can change. |
|
||
* **Isolated State:** All data for your application is stored within the context of its `AccountId`. It's like having a dedicated key-value store or a NoSQL document database scoped specifically to your application. One application cannot directly tamper with the raw storage of another. | ||
* **Mutability with Control:** While the history of *changes* to this state is cryptographically secured and immutable (forming the blockchain), the *current state* of your application's data is indeed mutable. However, these mutations are not arbitrary. They can only occur by invoking the logic defined within your smart contract – your application's backend code. You define the rules for how state can change. | ||
* **Data Replication & Availability:** This application state isn't just on one machine. The NEAR network, composed of many independent "[validator" nodes](/protocol/network/validators), replicates this state. This is analogous to a distributed database system with master-master replication. If some nodes go offline, the network continues to operate, and your application's state remains available. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* **Data Replication & Availability:** This application state isn't just on one machine. The NEAR network, composed of many independent "[validator" nodes](/protocol/network/validators), replicates this state. This is analogous to a distributed database system with master-master replication. If some nodes go offline, the network continues to operate, and your application's state remains available. | |
* **Data Replication & Availability:** This application state isn't just on one machine. The NEAR network, composed of many independent "[validator nodes](/protocol/network/validators)", replicates this state. This is analogous to a distributed database system with master-master replication. If some nodes go offline, the network continues to operate, and your application's state remains available. |
|
||
## Smart Contracts in Rust: The Twitter Example | ||
|
||
Now, let's see how this translates into code. Your backend logic on NEAR is encapsulated in a smart contract. As mentioned, these contracts are compiled to [WebAssembly (Wasm)](/smart-contracts/anatomy/wasm), allowing you to use languages like [Rust](/tools/sdk). Rust is a popular choice due to its performance, safety features, and strong tooling support within the NEAR ecosystem. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I see we don't have a dedicated page to WebAssembly on docs, so I would just remove the link.
Now, let's see how this translates into code. Your backend logic on NEAR is encapsulated in a smart contract. As mentioned, these contracts are compiled to [WebAssembly (Wasm)](/smart-contracts/anatomy/wasm), allowing you to use languages like [Rust](/tools/sdk). Rust is a popular choice due to its performance, safety features, and strong tooling support within the NEAR ecosystem. | |
Now, let's see how this translates into code. Your backend logic on NEAR is encapsulated in a smart contract. As mentioned, these contracts are compiled to WebAssembly (Wasm), allowing you to use languages like [Rust](/tools/sdk). Rust is a popular choice due to its performance, safety features, and strong tooling support within the NEAR ecosystem. |
The code that defines how your application's state can be read and modified is what we call a "[smart contract](/smart-contracts/what-is)." | ||
|
||
* **Your Business Logic:** This is where you write your application's rules. For our Twitter example, this logic will define how a tweet is created, who can post it, how tweets are retrieved, etc. | ||
* **Execution Environment:** This code doesn't run on a traditional OS. It's compiled into [WebAssembly (Wasm)](/smart-contracts/anatomy/wasm), a highly efficient and sandboxed binary format. This Wasm code is what's stored on the NEAR platform under your application's `AccountId` and executed by the validator nodes. The use of Wasm means you can write this logic in several familiar languages, with [Rust](/tools/sdk) being a primary and robust choice offering strong safety and performance. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As I see we don't have a dedicated page to WebAssembly on docs, so I would just remove the link.
* **Execution Environment:** This code doesn't run on a traditional OS. It's compiled into [WebAssembly (Wasm)](/smart-contracts/anatomy/wasm), a highly efficient and sandboxed binary format. This Wasm code is what's stored on the NEAR platform under your application's `AccountId` and executed by the validator nodes. The use of Wasm means you can write this logic in several familiar languages, with [Rust](/tools/sdk) being a primary and robust choice offering strong safety and performance. | |
* **Execution Environment:** This code doesn't run on a traditional OS. It's compiled into WebAssembly (Wasm), a highly efficient and sandboxed binary format. This Wasm code is what's stored on the NEAR platform under your application's `AccountId` and executed by the validator nodes. The use of Wasm means you can write this logic in several familiar languages, with [Rust](/tools/sdk) being a primary and robust choice offering strong safety and performance. |
// This smart contract implements a Twitter-like platform on the NEAR blockchain. | ||
// For backend engineers new to blockchain, think of this as a REST API service that: | ||
// - Stores data permanently on a distributed database (the blockchain) | ||
// - Has no central server - it runs on thousands of nodes worldwide |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// - Has no central server - it runs on thousands of nodes worldwide | |
// - Has no central server - it runs on hundreds of nodes worldwide |
|
||
These are "call" methods (marked `&mut self` in Rust) because they modify the contract's state. | ||
|
||
* **Transactions:** To execute these, a user (or an application acting on their behalf) constructs a [transaction](/protocol/transactions/overview). This transaction specifies: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* **Transactions:** To execute these, a user (or an application acting on their behalf) constructs a [transaction](/protocol/transactions/overview). This transaction specifies: | |
* **Transactions:** To execute these, a user (or an application acting on their behalf) constructs a [transaction](/protocol/transactions). This transaction specifies: |
* Once deployed, your smart contract logic cannot be easily shut down or tampered with by a single entity, including the original developer (unless specific upgrade mechanisms are built in and governed by clear rules). This provides a degree of censorship resistance for applications and their data. | ||
|
||
6. **Fast Finality and Scalable by Design:** | ||
* NEAR's ~1-2 second [finality](/protocol/transactions/overview#transaction-lifecycle--finality) means transactions are quickly confirmed and irreversible, providing a responsive user experience for a decentralized system. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* NEAR's ~1-2 second [finality](/protocol/transactions/overview#transaction-lifecycle--finality) means transactions are quickly confirmed and irreversible, providing a responsive user experience for a decentralized system. | |
* NEAR's ~1-2 second [finality](/protocol/transaction-execution) means transactions are quickly confirmed and irreversible, providing a responsive user experience for a decentralized system. |
I generated it with multiple AI tools and I am still reviewing it myself...